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