Skip to content
munrocket edited this page Aug 21, 2019 · 20 revisions

Install it from package npm install double.js or add script on page <script src="http://unpkg.com/double.js"></script>

Initialize is on page with ES5, ES6 or typescript

import Double as D from 'double.js';
var D = require('double.js');

Try to calculate something, here example with R = sqrt(a^2 + b^2)

let R = a.sqr().add(b.sqr()).sqrt();

And example with static method, you need to clone first argument in static method before usage.

let R = D.sqrt(D.add22(D.sqr2(D.clone(a)), D.sqr2(D.clone(b)));

Here full API specification, mutable variable tagged with exclamation mark (!). You can predict theoretical performance time with column Relative time, for example r.pow(3) in 34.5 times slower than `r.mul(r).mul(r).

Description Static method Instance method Relative time
Constructors new D([a, b])
-//- D.clone(X)
-//- D.fromSum11(a, b) 6 flop
-//- D.fromMul11(a, b) 17 flop
-//- D.fromSqr1(a) 12 flop
-//- D.fromNumber(number) new D(number)
-//- D.fromString(string) new D('double_number')
Converters X.toNumber()
-//- X.toExponential(precision)
Addition D.add22(X!, Y) X.add(Y) 22 flop
-//- D.add21(X!, a) -//- 10 flop
Subtraction D.sub22(X!, Y) X.sub(Y) 22 flop
-//- D.sub21(X!, a) -//- 10 flop
Multiplication D.mul22(X!, Y) X.mul(Y) 24 flop
-//- D.mul21(X!, a) -//- 23 flop
Mult. to a=2^n D.mul21pow2(X!, a) 2 flop
Division D.div22(X!, a) X.div(Y) 27 flop
-//- D.div21(X!, a) -//- 25 flop
Power D.pow22(X!, Y) X.pow(Y) ~2588 flop
Power of integer D.pow21n(X!, n) 24*log2(n) flop
Absolute value D.abs2(X!) X.abs()
Negate D.neg2(X!) X.neg()
Inverse D.inv2(X!) X.inv() 27 flop
Square D.sqr2(X!) X.sqr() 18 flop
Square root D.sqrt2(X!) X.sqrt() ~30 flop
Exponential fn. D.exp2(X!) X.exp() 1264 flop
Natural logarithm D.ln2(X!) X.ln() ~1264+60 flop
Hyperbolic sine D.sinh2(X!) X.sinh() 1264+53 flop
Hyperbolic cosine D.cosh2(X!) X.cosh() 1264+53 flop
Equals D.eq22(X, Y) X.eq(Y)
-//- D.eq21(X, a) -//-
Not equal D.ne22(X, Y) X.ne(Y)
-//- D.ne21(X, a) -//-
Greater than D.gt22(X, Y) X.gt(Y)
-//- D.gt21(X, a) -//-
Greater or equal D.ge22(X, Y) X.ge(Y)
-//- D.ge21(X, a) -//-
Less than D.lt22(X, Y) X.lt(Y)
-//- D.lt21(X, a) -//-
Less or equal D.le22(X, Y) X.le(Y)
-//- D.le21(X, a) -//-

Also you can find example here or in benchmark.js

Clone this wiki locally