diff --git a/API.png b/API.png index a32efa1..e17f1bd 100644 Binary files a/API.png and b/API.png differ diff --git a/index.html b/index.html index cfee767..ba795ce 100644 --- a/index.html +++ b/index.html @@ -61,7 +61,7 @@ li span{float:right;margin-right:10px;color:#c0c0c0} API CONSTRUCTOR -
+ Methodsobject
: object
Returns a new independent Decimal constructor with configuration settings as described by
- object
(see config
), or with the same
+ object
(see set
), or with the same
settings as this
Decimal constructor if object
is omitted.
Decimal.config({ precision: 5 }) +Decimal.set({ precision: 5 }) D9 = Decimal.clone({ precision: 9 }) a = new Decimal(1) @@ -461,7 +461,7 @@ b.div(3) // 0.333333333 // D9 = Decimal.clone({ precision: 9 }) is equivalent to: D9 = Decimal.clone() -D9.config({ precision: 9 })+D9.set({ precision: 9 })
It is not inefficient in terms of memory usage to use multiple Decimal constructors as functions are shared between them. @@ -469,45 +469,6 @@ D9.config({ precision: 9 }) -
.config(object) ⇒ Decimal constructor
- object
: object
- Configures the 'global' settings for this
particular Decimal constructor, i.e.
- the settings which apply to operations performed on the Decimal instances created by it.
-
Returns this
Decimal constructor.
- The configuration object, object
, can contain some or all of the properties
- described in detail at Properties and shown in the
- example below.
-
- The values of the configuration object properties are checked for validity and then stored as
- equivalently-named properties of this
Decimal constructor.
-
Throws on an invalid object
or configuration property value.
-// Defaults -Decimal.config({ - precision: 20, - rounding: 4, - toExpNeg: -7, - toExpPos: 21, - maxE: 9e15, - minE: -9e15, - modulo: 1, - crypto: undefined -})-
- The properties of a Decimal constructor can also be set by direct assignment, but that will - by-pass the validity checking that this method performs - which is not a problem if the user - knows that the checks are unnecessary. -
- - -.cos(x) ⇒ Decimal
x
: number|string|Decimal
See cosine
.
If the value of this
Decimal constructor's
- crypto
property is undefined
or
- true
, and the crypto
object is available in the host environment,
- the random digits of the return value are generated by either
- crypto.getRandomValues
(Web Cryptography API in modern browsers) or
- crypto.randomBytes
(Node.js), otherwise, if the the value of the property is
- false
, or the crypto
object is not available, the return value is
- generated by Math.random
(fastest).
+ crypto
property is true
, and the
+ crypto
object is available in the host environment, the random digits of the
+ return value are generated by either crypto.getRandomValues
(Web Cryptography API
+ in modern browsers) or crypto.randomBytes
(Node.js), otherwise, if the the value
+ of the property is false
the return value is generated by
+ Math.random
(fastest).
If the value of this
Decimal constructor's
@@ -733,7 +693,7 @@ a.equals(b) // true
If one of the crypto
methods is used, the value of the returned Decimal should be
cryptographically-secure and statistically indistinguishable from a random value.
Decimal.config({ precision: 10 }) ++Decimal.set({ precision: 10 }) Decimal.random() // '0.4117936847' Decimal.random(20) // '0.78193327636914089009'@@ -748,6 +708,44 @@ a.equals(b) // true
.set(object) ⇒ Decimal constructor
object
: object
+ Configures the 'global' settings for this
particular Decimal constructor, i.e.
+ the settings which apply to operations performed on the Decimal instances created by it.
+
Returns this
Decimal constructor.
+ The configuration object, object
, can contain some or all of the properties
+ described in detail at Properties and shown in the
+ example below.
+
+ The values of the configuration object properties are checked for validity and then stored as
+ equivalently-named properties of this
Decimal constructor.
+
Throws on an invalid object
or configuration property value.
+// Defaults +Decimal.set({ + precision: 20, + rounding: 4, + toExpNeg: -7, + toExpPos: 21, + maxE: 9e15, + minE: -9e15, + modulo: 1, + crypto: false +})+
+ The properties of a Decimal constructor can also be set by direct assignment, but that will + by-pass the validity checking that this method performs - this is not a problem if the user + knows that the assingment is valid. +
+Decimal.precision = 40+ + +
.sign(x) ⇒ number
x
: number|string|Decimal
Not a rounding mode, see modulo |
Decimal.config({ rounding: Decimal.ROUND_CEIL }) -Decimal.config({ rounding: 2 }) // equivalent +Decimal.set({ rounding: Decimal.ROUND_CEIL }) +Decimal.set({ rounding: 2 }) // equivalent Decimal.rounding // 2@@ -1875,7 +1873,7 @@ y.sd(true) // '6'
7
, i.e. ROUND_HALF_CEIL
.
-Decimal.config({ rounding: 4 }) +Decimal.set({ rounding: 4 }) x = 1234.5 x.round() // '1235' @@ -2316,7 +2314,7 @@ new Decimal(1217652.23).pow('98765.489305603941') An example of incorrect rounding:-Decimal.config({ precision: 20, rounding: 1 }) +Decimal.set({ precision: 20, rounding: 1 }) new Decimal(28).pow('6.166675020000903537297764507632802193308677149') // 839756321.64088511As the exact mathematical result begins
@@ -2388,7 +2386,7 @@ y.toPrecision(5) // '45.600'
Throws on an invalid sd
or rm
value.
-Decimal.config({ precision: 5, rounding: 4 }) +Decimal.set({ precision: 5, rounding: 4 }) x = new Decimal(9876.54321) x.toSignificantDigits() // '9876.5' @@ -2410,10 +2408,10 @@ x // '9876.54321'
x = new Decimal(750000) x.toString() // '750000' -Decimal.config({ toExpPos: 5 }) +Decimal.set({ toExpPos: 5 }) x.toString() // '7.5e+5' -Decimal.config({ precision: 4 }); +Decimal.set({ precision: 4 }) y = new Decimal('1.23456789') y.toString() // '1.23456789'@@ -2632,8 +2630,8 @@ z = x.multiply(y) // 4.1400000 -