From 65a6fbf6ffdd5431392b48f00e7a03b6bdfab48b Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Sat, 10 Mar 2018 22:55:05 +0000 Subject: [PATCH] v10.0.0 --- index.html | 127 ++++++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 59 deletions(-) diff --git a/index.html b/index.html index 6a3872c..b77f746 100644 --- a/index.html +++ b/index.html @@ -219,7 +219,7 @@ li span{float:right;margin-right:10px;color:#c0c0c0} The library is incorporated into this page, so it should be available in the console now.

- +

API

@@ -921,6 +921,9 @@ Decimal.precision = 0 toNearest and truncated.

+

+ See Pi for the precision limit of the trigonometric methods. +

Decimal.set({ precision: 5 })
 Decimal.precision                  // 5
@@ -1286,7 +1289,7 @@ y.cmp(NaN) // NaN Domain: [-Infinity, Infinity]
Range: [-1, 1]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0.25)
 x.cosine()                      // '0.96891242171064478414'
@@ -1436,7 +1439,7 @@ new Decimal(1).gte(x)                    // true
Domain: [-Infinity, Infinity]
Range: [1, Infinity]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(1)
 x.hyperbolicCosine()                     // '1.5430806348152437785'
@@ -1455,7 +1458,7 @@ y.cosh()                                 // '1.1276259652063807852'
Domain: [-Infinity, Infinity]
Range: [-Infinity, Infinity]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(1)
 x.hyperbolicSine()                       // '1.1752011936438014569'
@@ -1474,7 +1477,7 @@ y.sinh()                                 // '0.52109530549374736162'
Domain: [-Infinity, Infinity]
Range: [-1, 1]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(1)
 x.hyperbolicTangent()                    // '0.76159415595576488812'
@@ -1493,7 +1496,7 @@ y.tanh()                                 // '0.4621171572600097585'
Domain: [-1, 1]
Range: [0, pi]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0)
 x.inverseCosine()                        // '1.5707963267948966192'
@@ -1514,7 +1517,7 @@ y.acos()                                 // '1.0471975511965977462'
Domain: [1, Infinity]
Range: [0, Infinity]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(5)
 x.inverseHyperbolicCosine()              // '2.2924316695611776878'
@@ -1535,7 +1538,7 @@ y.acosh()                                // '4.6050701709847571595'
Domain: [-Infinity, Infinity]
Range: [-Infinity, Infinity]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(5)
 x.inverseHyperbolicSine()                // '2.3124383412727526203'
@@ -1556,7 +1559,7 @@ y.asinh()                                // '4.6052701709914238266'
Domain: [-1, 1]
Range: [-Infinity, Infinity]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0.5)
 x.inverseHyperbolicTangent()             // '0.5493061443340548457'
@@ -1575,7 +1578,7 @@ y.atanh()                                // '0.97295507452765665255'
Domain: [-1, 1]
Range: [-pi/2, pi/2]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0.5)
 x.inverseSine()                          // '0.52359877559829887308'
@@ -1594,7 +1597,7 @@ y.asin()                                 // '0.84806207898148100805'
Domain: [-Infinity, Infinity]
Range: [-pi/2, pi/2]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0.5)
 x.inverseTangent()                       // '0.46364760900080611621'
@@ -1746,7 +1749,8 @@ y.log(2)                                 // '8'

Logarithms to base 2 or 10 will always be correctly rounded.

See toPower for the circumstances in which this method may - return an incorrectly rounded result. + return an incorrectly rounded result, and see naturalLogarithm + for the precision limit.

The performance of this method degrades exponentially with increasing digits.

@@ -1933,7 +1937,7 @@ x // '1234.5' Domain: [-Infinity, Infinity]
Range: [-1, 1]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0.5)
 x.sine()                                 // '0.47942553860420300027'
@@ -1975,7 +1979,7 @@ y.sqrt().eq( y.pow(0.5) )                // true
Domain: [-Infinity, Infinity]
Range: [-Infinity, Infinity]

-

See Pi.

+

See Pi for the precision limit of this method.

 x = new Decimal(0.5)
 x.tangent()                              // '0.54630248984379051326'
@@ -2050,8 +2054,8 @@ x.toBinary(1)                            // '0b1p+8'

Throws on an invalid dp or rm value.

 x = new Decimal(12.34567)
-x.toDecimalPlaces(0)                // '12'
-x.toDecimalPlaces(1, 0)             // '12.3'
+x.toDecimalPlaces(0)                      // '12'
+x.toDecimalPlaces(1, Decimal.ROUND_UP)    // '12.3'
 
 y = new Decimal(9876.54321)
 y.toDP(3)                           // '9876.543'
@@ -2088,15 +2092,15 @@ y.toDP(1, Decimal.ROUND_DOWN)       // '9876.5'
 x = 45.6
 y = new Decimal(x)
-x.toExponential()              // '4.56e+1'
-y.toExponential()              // '4.56e+1'
-x.toExponential(0)             // '5e+1'
-y.toExponential(0)             // '5e+1'
-x.toExponential(1)             // '4.6e+1'
-y.toExponential(1)             // '4.6e+1'
-y.toExponential(1, 1)          // '4.5e+1'  (ROUND_DOWN)
-x.toExponential(3)             // '4.560e+1'
-y.toExponential(3)             // '4.560e+1'
+x.toExponential() // '4.56e+1' +y.toExponential() // '4.56e+1' +x.toExponential(0) // '5e+1' +y.toExponential(0) // '5e+1' +x.toExponential(1) // '4.6e+1' +y.toExponential(1) // '4.6e+1' +y.toExponential(1, Decimal.ROUND_DOWN) // '4.5e+1' +x.toExponential(3) // '4.560e+1' +y.toExponential(3) // '4.560e+1' @@ -2136,14 +2140,14 @@ y.toExponential(3) // '4.560e+1'
 x = 3.456
 y = new Decimal(x)
-x.toFixed()              // '3'
-y.toFixed()              // '3.456'
-y.toFixed(0)             // '3'
-x.toFixed(2)             // '3.46'
-y.toFixed(2)             // '3.46'
-y.toFixed(2, 1)          // '3.45'  (ROUND_DOWN)
-x.toFixed(5)             // '3.45600'
-y.toFixed(5)             // '3.45600'
+x.toFixed() // '3' +y.toFixed() // '3.456' +y.toFixed(0) // '3' +x.toFixed(2) // '3.46' +y.toFixed(2) // '3.46' +y.toFixed(2, Decimal.ROUND_DOWN) // '3.45' +x.toFixed(5) // '3.45600' +y.toFixed(5) // '3.45600' @@ -2215,25 +2219,16 @@ x.toHex(1) // '0x1p+8'
- toNearest.toNearest(n [, rm]) ⇒ Decimal + toNearest.toNearest(x [, rm]) ⇒ Decimal

x: number|string|Decimal
rm: number: integer, 0 to 8 inclusive

- Returns a new Decimal whose value is the nearest multiple of x to the value of - this Decimal. -

-

- If the value of this Decimal is equidistant from two multiples of x, the rounding - mode rm, or rounding if rm is - omitted, determines the direction of the nearest. -

-

- In this context, rounding mode ROUND_HALF_UP is - interpreted the same as rounding mode ROUND_UP, and so - on, i.e. the rounding is either up, down, to ceil, to floor or to even. + Returns a new Decimal whose value is the nearest multiple of x in the direction + of rounding mode rm, or rounding if + rm is omitted, to the value of this Decimal.

The return value will always have the same sign as this Decimal, unless either this Decimal @@ -2246,11 +2241,11 @@ x.toHex(1) // '0x1p+8'

 x = new Decimal(1.39)
-x.toNearest(0.25)              // '1.5'
+x.toNearest(0.25)                        // '1.5'
 
-y = new Decimal(0.75)          // equidistant from 0.5 and 1
-y.toNearest(0.5, 0)            // '1'    (ROUND_UP)
-y.toNearest(0.5, 1)            // '0.5'  (ROUND_DOWN)
+y = new Decimal(9.499) +y.toNearest(0.5, Decimal.ROUND_UP) // '9.5' +y.toNearest(0.5, Decimal.ROUND_DOWN) // '9' @@ -2398,8 +2393,8 @@ x.toPrecision() // '45.6' y.toPrecision() // '45.6' x.toPrecision(1) // '5e+1' y.toPrecision(1) // '5e+1' -y.toPrecision(2, 0) // '4.6e+1' (ROUND_UP) -y.toPrecision(2, 1) // '4.5e+1' (ROUND_DOWN) +y.toPrecision(2, Decimal.ROUND_UP) // '4.6e+1' +y.toPrecision(2, Decimal.DOWN) // '4.5e+1' x.toPrecision(5) // '45.600' y.toPrecision(5) // '45.600' @@ -2608,13 +2603,27 @@ try {

It has a precision of 1025 digits, meaning that the trigonometric methods - can accurately calculate up to at least 1000 digits. + can calculate up to just over 1000 digits, but the actual figure depends on the + precision of the argument passed to them. To calculate the actual figure use: +

+

maximum_result_precision = 1000 - argument_precision

+ For example, the following both work fine: +
+Decimal.set({precision: 991}).tan(123456789)
+Decimal.set({precision: 9}).tan(991_digit_number)
+

+ as, for each, the result precision plus the argument precision, i.e. 991 + 9 and + 9 + 991, is less than or equal to 1000.

If greater precision is required then the value of PI will need to be extended to - about 25 digits more than the precision required. + about 25 digits more than the precision required. The time taken by the methods + will then be the limiting factor. +

+

+ The value can also be shortened to reduce the size of the source file if such high precision + is not required.

-

The value can also be shortened to reduce the size of the source file.

To get the value of pi:

 pi = Decimal.acos(-1)
@@ -2670,10 +2679,10 @@ z = x.multiply(y) // 4.1400000

- +