From a821788a7c95383c2be3318993eae58ed489ca90 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Sat, 10 Mar 2018 21:57:13 +0000 Subject: [PATCH] Explain trig precision limits --- doc/API.html | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/doc/API.html b/doc/API.html index ae5f05d..600ec0e 100644 --- a/doc/API.html +++ b/doc/API.html @@ -916,6 +916,9 @@ Decimal.precision = 0 toNearest and truncated.

+

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

Decimal.set({ precision: 5 })
 Decimal.precision                  // 5
@@ -1281,7 +1284,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'
@@ -1431,7 +1434,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'
@@ -1450,7 +1453,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'
@@ -1469,7 +1472,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'
@@ -1488,7 +1491,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'
@@ -1509,7 +1512,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'
@@ -1530,7 +1533,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'
@@ -1551,7 +1554,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'
@@ -1570,7 +1573,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'
@@ -1589,7 +1592,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'
@@ -1741,7 +1744,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.

@@ -1928,7 +1932,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'
@@ -1970,7 +1974,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'
@@ -2235,7 +2239,7 @@ x = new Decimal(1.39)
 x.toNearest(0.25)                        // '1.5'
 
 y = new Decimal(9.499)
-y.toNearest(0.5, Decimal.ROUND_UP)       // '9.5'    
+y.toNearest(0.5, Decimal.ROUND_UP)       // '9.5'
 y.toNearest(0.5, Decimal.ROUND_DOWN)     // '9'
@@ -2594,13 +2598,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)