Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gmp-wasm

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gmp-wasm - npm Package Compare versions

Comparing version 0.9.4 to 1.0.0

dist/types/bindingTypes.d.ts

8

CHANGELOG.md

@@ -0,1 +1,9 @@

## 1.0.0 (Apr 9, 2022)
* **BREAKING CHANGES**:
* exponent2() was renamed to exponent()
* isPrime() was renamed to isProbablyPrime()
* New documentation based on TypeDoc
* More strict TS types
* Update all dependencies
## 0.9.4 (Dec 21, 2021)

@@ -2,0 +10,0 @@ * Fix uninitialized usage of mpz_t (by Yuri Stuken)

302

dist/types/float.d.ts

@@ -1,2 +0,2 @@

import type { GMPFunctions } from './functions';
import { GMPFunctions } from './functions';
import { Integer } from './integer';

@@ -46,48 +46,87 @@ import { Rational } from './rational';

div(val: AllTypes): Float;
/** Returns the integer square root number of this number. */
/** Returns the square root. */
sqrt(): Float;
/** Returns the reciprocal square root. */
invSqrt(): Float;
/** Returns the cube root. */
cbrt(): Float;
/** Returns the n-th root. */
nthRoot(nth: number): Float;
/** Returns the number with inverted sign. */
neg(): Float;
/** Returns the absolute value of this number. */
/** Returns the absolute value. */
abs(): Float;
factorial(): any;
/** Returns the factorial */
factorial(): Float;
/** Returns true if the number is an integer */
isInteger(): boolean;
/** Returns true if the number is zero */
isZero(): boolean;
/** Returns true if the number is a regular number (i.e., neither NaN, nor an infinity nor zero) */
isRegular(): boolean;
/** Return true if the number is an ordinary number (i.e., neither NaN nor an infinity) */
isNumber(): boolean;
/** Returns true if the number is an infinity */
isInfinite(): boolean;
/** Returns true if the number is NaN */
isNaN(): boolean;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
/** Returns the natural logarithm */
ln(): Float;
/** Returns the base 2 logarithm */
log2(): Float;
/** Returns the base 10 logarithm */
log10(): Float;
/** Returns the exponential (e^x) */
exp(): Float;
/** Returns 2 to the power of current number (2^x) */
exp2(): Float;
/** Returns 10 to the power of current number (10^x) */
exp10(): Float;
/** Returns this number exponentiated to the given value. */
pow(val: Float | number): Float;
/** Returns the sine */
sin(): Float;
/** Returns the cosine */
cos(): Float;
/** Returns the tangent */
tan(): Float;
/** Returns the secant */
sec(): Float;
/** Returns the cosecant */
csc(): Float;
/** Returns the cotangent */
cot(): Float;
/** Returns the arc-cosine */
acos(): Float;
/** Returns the arc-sine */
asin(): Float;
/** Returns the arc-tangent */
atan(): Float;
/** Returns the hyperbolic sine */
sinh(): Float;
/** Returns the hyperbolic cosine */
cosh(): Float;
/** Returns the hyperbolic tangent */
tanh(): Float;
/** Returns the hyperbolic secant */
sech(): Float;
/** Returns the hyperbolic cosecant */
csch(): Float;
/** Returns the hyperbolic cotangent */
coth(): Float;
/** Returns the inverse hyperbolic cosine */
acosh(): Float;
/** Returns the inverse hyperbolic sine */
asinh(): Float;
/** Returns the inverse hyperbolic tangent */
atanh(): Float;

@@ -128,3 +167,5 @@ /** Calculate exponential integral */

ai(): Float;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value into a JavaScript number */
toNumber(): number;

@@ -149,8 +190,15 @@ /** Rounds to the next higher or equal representable integer */

remainder(y: Float): Float;
/** Return next value towards +∞ */
nextAbove(): Float;
/** Return next value towards -∞ */
nextBelow(): Float;
exponent2(): number;
/** Returns the exponent of x, assuming that x is a non-zero ordinary number and the significand is considered in [1/2, 1). */
exponent(): number;
/** Converts the number to string */
toString(radix?: number): string;
toFixed(digits?: number, radix?: number): any;
/** Formats the number using fixed-point notation */
toFixed(digits?: number, radix?: number): string;
/** Converts the number to an integer */
toInteger(): Integer;
/** Converts the number to a rational number */
toRational(): Rational;

@@ -175,48 +223,87 @@ };

div(val: AllTypes): Float;
/** Returns the integer square root number of this number. */
/** Returns the square root. */
sqrt(): Float;
/** Returns the reciprocal square root. */
invSqrt(): Float;
/** Returns the cube root. */
cbrt(): Float;
/** Returns the n-th root. */
nthRoot(nth: number): Float;
/** Returns the number with inverted sign. */
neg(): Float;
/** Returns the absolute value of this number. */
/** Returns the absolute value. */
abs(): Float;
factorial(): any;
/** Returns the factorial */
factorial(): Float;
/** Returns true if the number is an integer */
isInteger(): boolean;
/** Returns true if the number is zero */
isZero(): boolean;
/** Returns true if the number is a regular number (i.e., neither NaN, nor an infinity nor zero) */
isRegular(): boolean;
/** Return true if the number is an ordinary number (i.e., neither NaN nor an infinity) */
isNumber(): boolean;
/** Returns true if the number is an infinity */
isInfinite(): boolean;
/** Returns true if the number is NaN */
isNaN(): boolean;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
/** Returns the natural logarithm */
ln(): Float;
/** Returns the base 2 logarithm */
log2(): Float;
/** Returns the base 10 logarithm */
log10(): Float;
/** Returns the exponential (e^x) */
exp(): Float;
/** Returns 2 to the power of current number (2^x) */
exp2(): Float;
/** Returns 10 to the power of current number (10^x) */
exp10(): Float;
/** Returns this number exponentiated to the given value. */
pow(val: Float | number): Float;
/** Returns the sine */
sin(): Float;
/** Returns the cosine */
cos(): Float;
/** Returns the tangent */
tan(): Float;
/** Returns the secant */
sec(): Float;
/** Returns the cosecant */
csc(): Float;
/** Returns the cotangent */
cot(): Float;
/** Returns the arc-cosine */
acos(): Float;
/** Returns the arc-sine */
asin(): Float;
/** Returns the arc-tangent */
atan(): Float;
/** Returns the hyperbolic sine */
sinh(): Float;
/** Returns the hyperbolic cosine */
cosh(): Float;
/** Returns the hyperbolic tangent */
tanh(): Float;
/** Returns the hyperbolic secant */
sech(): Float;
/** Returns the hyperbolic cosecant */
csch(): Float;
/** Returns the hyperbolic cotangent */
coth(): Float;
/** Returns the inverse hyperbolic cosine */
acosh(): Float;
/** Returns the inverse hyperbolic sine */
asinh(): Float;
/** Returns the inverse hyperbolic tangent */
atanh(): Float;

@@ -257,3 +344,5 @@ /** Calculate exponential integral */

ai(): Float;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value into a JavaScript number */
toNumber(): number;

@@ -278,8 +367,15 @@ /** Rounds to the next higher or equal representable integer */

remainder(y: Float): Float;
/** Return next value towards +∞ */
nextAbove(): Float;
/** Return next value towards -∞ */
nextBelow(): Float;
exponent2(): number;
/** Returns the exponent of x, assuming that x is a non-zero ordinary number and the significand is considered in [1/2, 1). */
exponent(): number;
/** Converts the number to string */
toString(radix?: number): string;
toFixed(digits?: number, radix?: number): any;
/** Formats the number using fixed-point notation */
toFixed(digits?: number, radix?: number): string;
/** Converts the number to an integer */
toInteger(): Integer;
/** Converts the number to a rational number */
toRational(): Rational;

@@ -303,48 +399,87 @@ };

div(val: AllTypes): Float;
/** Returns the integer square root number of this number. */
/** Returns the square root. */
sqrt(): Float;
/** Returns the reciprocal square root. */
invSqrt(): Float;
/** Returns the cube root. */
cbrt(): Float;
/** Returns the n-th root. */
nthRoot(nth: number): Float;
/** Returns the number with inverted sign. */
neg(): Float;
/** Returns the absolute value of this number. */
/** Returns the absolute value. */
abs(): Float;
factorial(): any;
/** Returns the factorial */
factorial(): Float;
/** Returns true if the number is an integer */
isInteger(): boolean;
/** Returns true if the number is zero */
isZero(): boolean;
/** Returns true if the number is a regular number (i.e., neither NaN, nor an infinity nor zero) */
isRegular(): boolean;
/** Return true if the number is an ordinary number (i.e., neither NaN nor an infinity) */
isNumber(): boolean;
/** Returns true if the number is an infinity */
isInfinite(): boolean;
/** Returns true if the number is NaN */
isNaN(): boolean;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
/** Returns the natural logarithm */
ln(): Float;
/** Returns the base 2 logarithm */
log2(): Float;
/** Returns the base 10 logarithm */
log10(): Float;
/** Returns the exponential (e^x) */
exp(): Float;
/** Returns 2 to the power of current number (2^x) */
exp2(): Float;
/** Returns 10 to the power of current number (10^x) */
exp10(): Float;
/** Returns this number exponentiated to the given value. */
pow(val: Float | number): Float;
/** Returns the sine */
sin(): Float;
/** Returns the cosine */
cos(): Float;
/** Returns the tangent */
tan(): Float;
/** Returns the secant */
sec(): Float;
/** Returns the cosecant */
csc(): Float;
/** Returns the cotangent */
cot(): Float;
/** Returns the arc-cosine */
acos(): Float;
/** Returns the arc-sine */
asin(): Float;
/** Returns the arc-tangent */
atan(): Float;
/** Returns the hyperbolic sine */
sinh(): Float;
/** Returns the hyperbolic cosine */
cosh(): Float;
/** Returns the hyperbolic tangent */
tanh(): Float;
/** Returns the hyperbolic secant */
sech(): Float;
/** Returns the hyperbolic cosecant */
csch(): Float;
/** Returns the hyperbolic cotangent */
coth(): Float;
/** Returns the inverse hyperbolic cosine */
acosh(): Float;
/** Returns the inverse hyperbolic sine */
asinh(): Float;
/** Returns the inverse hyperbolic tangent */
atanh(): Float;

@@ -385,3 +520,5 @@ /** Calculate exponential integral */

ai(): Float;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value into a JavaScript number */
toNumber(): number;

@@ -406,8 +543,15 @@ /** Rounds to the next higher or equal representable integer */

remainder(y: Float): Float;
/** Return next value towards +∞ */
nextAbove(): Float;
/** Return next value towards -∞ */
nextBelow(): Float;
exponent2(): number;
/** Returns the exponent of x, assuming that x is a non-zero ordinary number and the significand is considered in [1/2, 1). */
exponent(): number;
/** Converts the number to string */
toString(radix?: number): string;
toFixed(digits?: number, radix?: number): any;
/** Formats the number using fixed-point notation */
toFixed(digits?: number, radix?: number): string;
/** Converts the number to an integer */
toInteger(): Integer;
/** Converts the number to a rational number */
toRational(): Rational;

@@ -432,48 +576,87 @@ };

div(val: AllTypes): Float;
/** Returns the integer square root number of this number. */
/** Returns the square root. */
sqrt(): Float;
/** Returns the reciprocal square root. */
invSqrt(): Float;
/** Returns the cube root. */
cbrt(): Float;
/** Returns the n-th root. */
nthRoot(nth: number): Float;
/** Returns the number with inverted sign. */
neg(): Float;
/** Returns the absolute value of this number. */
/** Returns the absolute value. */
abs(): Float;
factorial(): any;
/** Returns the factorial */
factorial(): Float;
/** Returns true if the number is an integer */
isInteger(): boolean;
/** Returns true if the number is zero */
isZero(): boolean;
/** Returns true if the number is a regular number (i.e., neither NaN, nor an infinity nor zero) */
isRegular(): boolean;
/** Return true if the number is an ordinary number (i.e., neither NaN nor an infinity) */
isNumber(): boolean;
/** Returns true if the number is an infinity */
isInfinite(): boolean;
/** Returns true if the number is NaN */
isNaN(): boolean;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
/** Returns the natural logarithm */
ln(): Float;
/** Returns the base 2 logarithm */
log2(): Float;
/** Returns the base 10 logarithm */
log10(): Float;
/** Returns the exponential (e^x) */
exp(): Float;
/** Returns 2 to the power of current number (2^x) */
exp2(): Float;
/** Returns 10 to the power of current number (10^x) */
exp10(): Float;
/** Returns this number exponentiated to the given value. */
pow(val: Float | number): Float;
/** Returns the sine */
sin(): Float;
/** Returns the cosine */
cos(): Float;
/** Returns the tangent */
tan(): Float;
/** Returns the secant */
sec(): Float;
/** Returns the cosecant */
csc(): Float;
/** Returns the cotangent */
cot(): Float;
/** Returns the arc-cosine */
acos(): Float;
/** Returns the arc-sine */
asin(): Float;
/** Returns the arc-tangent */
atan(): Float;
/** Returns the hyperbolic sine */
sinh(): Float;
/** Returns the hyperbolic cosine */
cosh(): Float;
/** Returns the hyperbolic tangent */
tanh(): Float;
/** Returns the hyperbolic secant */
sech(): Float;
/** Returns the hyperbolic cosecant */
csch(): Float;
/** Returns the hyperbolic cotangent */
coth(): Float;
/** Returns the inverse hyperbolic cosine */
acosh(): Float;
/** Returns the inverse hyperbolic sine */
asinh(): Float;
/** Returns the inverse hyperbolic tangent */
atanh(): Float;

@@ -514,3 +697,5 @@ /** Calculate exponential integral */

ai(): Float;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value into a JavaScript number */
toNumber(): number;

@@ -535,8 +720,15 @@ /** Rounds to the next higher or equal representable integer */

remainder(y: Float): Float;
/** Return next value towards +∞ */
nextAbove(): Float;
/** Return next value towards -∞ */
nextBelow(): Float;
exponent2(): number;
/** Returns the exponent of x, assuming that x is a non-zero ordinary number and the significand is considered in [1/2, 1). */
exponent(): number;
/** Converts the number to string */
toString(radix?: number): string;
toFixed(digits?: number, radix?: number): any;
/** Formats the number using fixed-point notation */
toFixed(digits?: number, radix?: number): string;
/** Converts the number to an integer */
toInteger(): Integer;
/** Converts the number to a rational number */
toRational(): Rational;

@@ -560,48 +752,87 @@ };

div(val: AllTypes): Float;
/** Returns the integer square root number of this number. */
/** Returns the square root. */
sqrt(): Float;
/** Returns the reciprocal square root. */
invSqrt(): Float;
/** Returns the cube root. */
cbrt(): Float;
/** Returns the n-th root. */
nthRoot(nth: number): Float;
/** Returns the number with inverted sign. */
neg(): Float;
/** Returns the absolute value of this number. */
/** Returns the absolute value. */
abs(): Float;
factorial(): any;
/** Returns the factorial */
factorial(): Float;
/** Returns true if the number is an integer */
isInteger(): boolean;
/** Returns true if the number is zero */
isZero(): boolean;
/** Returns true if the number is a regular number (i.e., neither NaN, nor an infinity nor zero) */
isRegular(): boolean;
/** Return true if the number is an ordinary number (i.e., neither NaN nor an infinity) */
isNumber(): boolean;
/** Returns true if the number is an infinity */
isInfinite(): boolean;
/** Returns true if the number is NaN */
isNaN(): boolean;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
/** Returns the natural logarithm */
ln(): Float;
/** Returns the base 2 logarithm */
log2(): Float;
/** Returns the base 10 logarithm */
log10(): Float;
/** Returns the exponential (e^x) */
exp(): Float;
/** Returns 2 to the power of current number (2^x) */
exp2(): Float;
/** Returns 10 to the power of current number (10^x) */
exp10(): Float;
/** Returns this number exponentiated to the given value. */
pow(val: Float | number): Float;
/** Returns the sine */
sin(): Float;
/** Returns the cosine */
cos(): Float;
/** Returns the tangent */
tan(): Float;
/** Returns the secant */
sec(): Float;
/** Returns the cosecant */
csc(): Float;
/** Returns the cotangent */
cot(): Float;
/** Returns the arc-cosine */
acos(): Float;
/** Returns the arc-sine */
asin(): Float;
/** Returns the arc-tangent */
atan(): Float;
/** Returns the hyperbolic sine */
sinh(): Float;
/** Returns the hyperbolic cosine */
cosh(): Float;
/** Returns the hyperbolic tangent */
tanh(): Float;
/** Returns the hyperbolic secant */
sech(): Float;
/** Returns the hyperbolic cosecant */
csch(): Float;
/** Returns the hyperbolic cotangent */
coth(): Float;
/** Returns the inverse hyperbolic cosine */
acosh(): Float;
/** Returns the inverse hyperbolic sine */
asinh(): Float;
/** Returns the inverse hyperbolic tangent */
atanh(): Float;

@@ -642,3 +873,5 @@ /** Calculate exponential integral */

ai(): Float;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value into a JavaScript number */
toNumber(): number;

@@ -663,8 +896,15 @@ /** Rounds to the next higher or equal representable integer */

remainder(y: Float): Float;
/** Return next value towards +∞ */
nextAbove(): Float;
/** Return next value towards -∞ */
nextBelow(): Float;
exponent2(): number;
/** Returns the exponent of x, assuming that x is a non-zero ordinary number and the significand is considered in [1/2, 1). */
exponent(): number;
/** Converts the number to string */
toString(radix?: number): string;
toFixed(digits?: number, radix?: number): any;
/** Formats the number using fixed-point notation */
toFixed(digits?: number, radix?: number): string;
/** Converts the number to an integer */
toInteger(): Integer;
/** Converts the number to a rational number */
toRational(): Rational;

@@ -671,0 +911,0 @@ };

@@ -5,2 +5,3 @@ import { Float, FloatFactory, FloatOptions, FloatRoundingMode } from './float';

import { Rational, RationalFactory } from './rational';
export * from './bindingTypes';
export { DivMode, FloatRoundingMode, GMPFunctions, };

@@ -7,0 +8,0 @@ export type { Float as FloatType, Integer as IntegerType, Rational as RationalType, FloatOptions, };

@@ -35,13 +35,21 @@ import type { GMPFunctions } from './functions';

pow(exp: Rational | Integer | number, mod?: Integer | number): Integer;
/** Returns the integer square root number of this number, rounded down. */
/** Returns the integer square root number, rounded down. */
sqrt(): Integer;
/** Returns the truncated integer part of the nth root */
nthRoot(nth: number): Integer;
/** Returns the factorial */
factorial(): Integer;
/** Returns the double factorial */
doubleFactorial(): Integer;
isPrime(reps?: number): boolean | 'probably-prime';
/** Determines whether a number is prime using some trial divisions, then reps Miller-Rabin probabilistic primality tests. */
isProbablyPrime(reps?: number): boolean | 'probably-prime';
/** Identifies primes using a probabilistic algorithm; the chance of a composite passing will be extremely small. */
nextPrime(): Integer;
/** Returns the greatest common divisor of this number and the given one. */
gcd(val: Integer | number): Integer;
/** Returns the least common multiple of this number and the given one. */
lcm(val: Integer | number): Integer;
/** Returns the one's complement. */
complement1(): Integer;
/** Returns the two's complement. */
complement2(): Integer;

@@ -76,14 +84,24 @@ /** Returns the integer bitwise-and combined with another integer. */

/** Creates new integer with the copy of binary representation of num to position offset. Optionally bitCount can be used to zero-pad the number to a specific number of bits. The least significant bit is number 0 */
writeTo(num: Integer, offset?: number, bitCount?: number): any;
writeTo(num: Integer, offset?: number, bitCount?: number): Integer;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value into a JavaScript number */
toNumber(): number;
/** Exports integer into an Uint8Array. Sign is ignored. */
toBuffer(littleEndian?: boolean): Uint8Array;
/** Converts the number to string */
toString(radix?: number): string;
/** Converts the number to a rational number */
toRational(): Rational;
/** Converts the number to a floating-point number */
toFloat(): Float;

@@ -90,0 +108,0 @@ };

@@ -24,2 +24,3 @@ import type { GMPFunctions } from './functions';

neg(): Rational;
/** Returns the inverse of the number. */
invert(): Rational;

@@ -30,13 +31,25 @@ /** Returns the absolute value of this number. */

div<T_3 extends AllTypes>(val: T_3): OutputType<T_3>;
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean;
/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean;
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean;
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean;
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean;
/** Returns the numerator of the number */
numerator(): Integer;
/** Returns the denominator of the number */
denominator(): Integer;
sign(): number;
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1;
/** Converts current value to a JavaScript number */
toNumber(): number;
/** Converts the number to string */
toString(): string;
/** Converts the number to an integer */
toInteger(): Integer;
/** Converts the number to a floating-point number */
toFloat(): Float;

@@ -43,0 +56,0 @@ };

38

package.json
{
"name": "gmp-wasm",
"version": "0.9.4",
"version": "1.0.0",
"description": "Arbitrary-precision Integer, Rational and Float types based on the GMP and MPFR libraries",

@@ -18,3 +18,4 @@ "main": "dist/index.umd.js",

"test": "jest --coverage",
"typedoc": "typedoc ./src/index.ts"
"typedoc": "typedoc ./src/index.ts",
"typedoc-serve": "npm run typedoc && npx serve -n docs"
},

@@ -58,23 +59,24 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-alias": "^3.1.8",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-typescript": "^8.3.0",
"@types/estree": "^0.0.50",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.6",
"binaryen": "^102.0.0",
"fflate": "^0.7.1",
"jest": "^27.3.1",
"rollup": "^2.59.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-typescript": "^8.3.1",
"@types/estree": "^0.0.51",
"@types/jest": "^27.4.1",
"@types/node": "^16.11.26",
"binaryen": "^106.0.0",
"fflate": "^0.7.3",
"jest": "^27.5.1",
"rollup": "^2.70.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-license": "^2.6.0",
"rollup-plugin-license": "^2.6.1",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"serve": "^13.0.2",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0",
"tslib": "^2.3.1",
"typedoc": "^0.22.8",
"typescript": "^4.4.4"
"typedoc": "^0.22.14",
"typescript": "^4.6.3"
}
}

@@ -17,3 +17,3 @@ # GMP-WASM

- Works even without Webpack or other bundlers
- Includes TypeScript type definitions, check API [here](https://paka.dev/npm/gmp-wasm).
- Includes TypeScript type definitions, check API [here](https://daninet.github.io/gmp-wasm).
- Zero dependencies

@@ -161,19 +161,19 @@ - Full minified and gzipped bundle has a size of ![Bundle size](https://img.badgesize.io/Daninet/gmp-wasm/binaries/index.umd.min.js?compression=gzip&label=minzipped%20size)

| Test | Avg. time | Speedup |
|-------------------------------------------------------------------------------------|-----------|----------|
| With JS built-in `BigInt` type | 130.20 ms | 1x |
| **gmp-wasm** `Integer()` high-level wrapper | 87.90 ms | 1.48x |
| Same as previous with delayed memory deallocation | 78.88 ms | 1.65x |
| **gmp-wasm** `MPZ` low-level functions | 53.93 ms | 2.41x |
| [decimal.js](https://www.npmjs.com/package/decimal.js) 10.3.1 with integer division | 426.99 ms | 0.30x |
| [big-integer](https://www.npmjs.com/package/big-integer) 1.6.51 | 129.98 ms | 1x |
| ----------------------------------------------------------------------------------- | --------- | -------- |
| With JS built-in `BigInt` type | 129 ms | 1x |
| **gmp-wasm** `Integer()` high-level wrapper | 88 ms | 1.47x |
| Same as previous with delayed memory deallocation | 78 ms | 1.65x |
| **gmp-wasm** `MPZ` low-level functions | 53 ms | 2.43x |
| [decimal.js](https://www.npmjs.com/package/decimal.js) 10.3.1 with integer division | 443 ms | 0.29x |
| [big-integer](https://www.npmjs.com/package/big-integer) 1.6.51 | 129 ms | 1x |
| ---------------------------- | -------- | -------- |
| **gmp-wasm** `Float()` high-level wrapper | 198.31 ms | 0.66x |
| Same as previous with delayed memory deallocation | 191.94 ms | 0.68x |
| **gmp-wasm** `MPFR` low-level functions | 135.49 ms | 0.96x |
| [decimal.js](https://www.npmjs.com/package/decimal.js) 10.3.1 with float division | 764.15 ms | 0.17x |
| **gmp-wasm** `Float()` high-level wrapper | 175 ms | 0.74x |
| Same as previous with delayed memory deallocation | 169 ms | 0.76x |
| **gmp-wasm** `MPFR` low-level functions | 118 ms | 1.09x |
| [decimal.js](https://www.npmjs.com/package/decimal.js) 10.3.1 with float division | 785 ms | 0.16x |
| ---------------------------- | -------- | -------- |
| **gmp-wasm** `Float(1).atan().mul(4)` | 0.65 ms | 200.31x |
| **gmp-wasm** `Float('0.5').asin().mul(6)` | 17.21 ms | 7.57x |
| **gmp-wasm** `Float(1).atan().mul(4)` | 0.6 ms | 215x |
| **gmp-wasm** `Float('0.5').asin().mul(6)` | 17 ms | 7.59x |
\* These measurements were made with `Node.js v16.13` on an Intel Kaby Lake desktop CPU. Source code is [here](https://github.com/Daninet/gmp-wasm/blob/master/benchmark/calcpi.js).
\* These measurements were made with `Node.js v16.14` on an Intel Kaby Lake desktop CPU. Source code is [here](https://github.com/Daninet/gmp-wasm/blob/master/benchmark/calcpi.js).

@@ -32,3 +32,3 @@ import { inflateSync } from 'fflate';

let heap = { HEAP8: null };
const heap = { HEAP8: new Uint8Array(0) };

@@ -35,0 +35,0 @@ const errorHandler = () => {

@@ -1,2 +0,3 @@

import type { GMPFunctions, mpfr_rnd_t } from './functions';
import { mpfr_rnd_t } from './bindingTypes';
import { GMPFunctions } from './functions';
import { Integer } from './integer';

@@ -294,3 +295,3 @@ import { Rational } from './rational';

/** Returns the integer square root number of this number. */
/** Returns the square root. */
sqrt(): Float {

@@ -302,2 +303,3 @@ const n = FloatFn(null, this.options);

/** Returns the reciprocal square root. */
invSqrt(): Float {

@@ -309,2 +311,3 @@ const n = FloatFn(null, this.options);

/** Returns the cube root. */
cbrt(): Float {

@@ -316,2 +319,3 @@ const n = FloatFn(null, this.options);

/** Returns the n-th root. */
nthRoot(nth: number): Float {

@@ -331,3 +335,3 @@ const n = FloatFn(null, this.options);

/** Returns the absolute value of this number. */
/** Returns the absolute value. */
abs(): Float {

@@ -339,3 +343,4 @@ const n = FloatFn(null, this.options);

factorial() {
/** Returns the factorial */
factorial(): Float {
const n = FloatFn(null, this.options);

@@ -350,26 +355,33 @@ if (gmp.mpfr_fits_uint_p(this.mpfr_t, this.rndMode) === 0) {

isInteger() {
/** Returns true if the number is an integer */
isInteger(): boolean {
return gmp.mpfr_integer_p(this.mpfr_t) !== 0;
},
isZero() {
/** Returns true if the number is zero */
isZero(): boolean {
return gmp.mpfr_zero_p(this.mpfr_t) !== 0;
},
isRegular() {
/** Returns true if the number is a regular number (i.e., neither NaN, nor an infinity nor zero) */
isRegular(): boolean {
return gmp.mpfr_regular_p(this.mpfr_t) !== 0;
},
isNumber() {
/** Return true if the number is an ordinary number (i.e., neither NaN nor an infinity) */
isNumber(): boolean {
return gmp.mpfr_number_p(this.mpfr_t) !== 0;
},
isInfinite() {
/** Returns true if the number is an infinity */
isInfinite(): boolean {
return gmp.mpfr_inf_p(this.mpfr_t) !== 0;
},
isNaN() {
/** Returns true if the number is NaN */
isNaN(): boolean {
return gmp.mpfr_nan_p(this.mpfr_t) !== 0;
},
/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean {

@@ -379,14 +391,18 @@ return compare(this.mpfr_t, val) === 0;

/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean {
return compare(this.mpfr_t, val) < 0;
},
/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean {
return compare(this.mpfr_t, val) <= 0;
},
/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean {
return compare(this.mpfr_t, val) > 0;
},
/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean {

@@ -396,2 +412,3 @@ return compare(this.mpfr_t, val) >= 0;

/** Returns the natural logarithm */
ln(): Float {

@@ -403,2 +420,3 @@ const n = FloatFn(null, this.options);

/** Returns the base 2 logarithm */
log2(): Float {

@@ -410,2 +428,3 @@ const n = FloatFn(null, this.options);

/** Returns the base 10 logarithm */
log10(): Float {

@@ -417,2 +436,3 @@ const n = FloatFn(null, this.options);

/** Returns the exponential (e^x) */
exp(): Float {

@@ -424,2 +444,3 @@ const n = FloatFn(null, this.options);

/** Returns 2 to the power of current number (2^x) */
exp2(): Float {

@@ -431,2 +452,3 @@ const n = FloatFn(null, this.options);

/** Returns 10 to the power of current number (10^x) */
exp10(): Float {

@@ -453,2 +475,3 @@ const n = FloatFn(null, this.options);

/** Returns the sine */
sin(): Float {

@@ -460,2 +483,3 @@ const n = FloatFn(null, this.options);

/** Returns the cosine */
cos(): Float {

@@ -467,2 +491,3 @@ const n = FloatFn(null, this.options);

/** Returns the tangent */
tan(): Float {

@@ -474,2 +499,3 @@ const n = FloatFn(null, this.options);

/** Returns the secant */
sec(): Float {

@@ -481,2 +507,3 @@ const n = FloatFn(null, this.options);

/** Returns the cosecant */
csc(): Float {

@@ -488,2 +515,3 @@ const n = FloatFn(null, this.options);

/** Returns the cotangent */
cot(): Float{

@@ -495,2 +523,3 @@ const n = FloatFn(null, this.options);

/** Returns the arc-cosine */
acos(): Float {

@@ -502,2 +531,3 @@ const n = FloatFn(null, this.options);

/** Returns the arc-sine */
asin(): Float {

@@ -509,2 +539,3 @@ const n = FloatFn(null, this.options);

/** Returns the arc-tangent */
atan(): Float {

@@ -516,2 +547,3 @@ const n = FloatFn(null, this.options);

/** Returns the hyperbolic sine */
sinh(): Float {

@@ -523,2 +555,3 @@ const n = FloatFn(null, this.options);

/** Returns the hyperbolic cosine */
cosh(): Float {

@@ -530,2 +563,3 @@ const n = FloatFn(null, this.options);

/** Returns the hyperbolic tangent */
tanh(): Float {

@@ -537,2 +571,3 @@ const n = FloatFn(null, this.options);

/** Returns the hyperbolic secant */
sech(): Float {

@@ -544,2 +579,3 @@ const n = FloatFn(null, this.options);

/** Returns the hyperbolic cosecant */
csch(): Float {

@@ -551,2 +587,3 @@ const n = FloatFn(null, this.options);

/** Returns the hyperbolic cotangent */
coth(): Float {

@@ -558,2 +595,3 @@ const n = FloatFn(null, this.options);

/** Returns the inverse hyperbolic cosine */
acosh(): Float {

@@ -565,2 +603,3 @@ const n = FloatFn(null, this.options);

/** Returns the inverse hyperbolic sine */
asinh(): Float {

@@ -572,2 +611,3 @@ const n = FloatFn(null, this.options);

/** Returns the inverse hyperbolic tangent */
atanh(): Float {

@@ -706,7 +746,9 @@ const n = FloatFn(null, this.options);

sign() {
return gmp.mpfr_sgn(this.mpfr_t);
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1 {
return gmp.mpfr_sgn(this.mpfr_t) as -1 | 0 | 1;
},
toNumber() {
/** Converts current value into a JavaScript number */
toNumber(): number {
return gmp.mpfr_get_d(this.mpfr_t, this.rndMode);

@@ -785,2 +827,3 @@ },

/** Return next value towards +∞ */
nextAbove(): Float {

@@ -792,2 +835,3 @@ const n = FloatFn(this, this.options);

/** Return next value towards -∞ */
nextBelow(): Float {

@@ -799,7 +843,9 @@ const n = FloatFn(this, this.options);

exponent2() {
/** Returns the exponent of x, assuming that x is a non-zero ordinary number and the significand is considered in [1/2, 1). */
exponent(): number {
return gmp.mpfr_get_exp(this.mpfr_t);
},
toString(radix?: number) {
/** Converts the number to string */
toString(radix?: number): string {
radix = radix ?? this.options.radix;

@@ -826,3 +872,4 @@ assertValidRadix(radix);

toFixed(digits = 0, radix?: number) {
/** Formats the number using fixed-point notation */
toFixed(digits = 0, radix?: number): string {
assertUint32(digits);

@@ -858,2 +905,3 @@ radix = radix ?? this.options.radix;

/** Converts the number to an integer */
toInteger(): Integer {

@@ -863,2 +911,3 @@ return ctx.intContext.Integer(this);

/** Converts the number to a rational number */
toRational(): Rational {

@@ -865,0 +914,0 @@ return ctx.rationalContext.Rational(this);

@@ -6,2 +6,4 @@ import { Float, FloatFactory, FloatOptions, FloatRoundingMode, getFloatContext } from './float';

export * from './bindingTypes';
export {

@@ -101,2 +103,3 @@ DivMode,

/** Resets the WASM instance (clears all previously allocated objects) */
reset: async () => {

@@ -103,0 +106,0 @@ return binding.reset();

@@ -242,3 +242,3 @@ import type { GMPFunctions } from './functions';

/** Returns the integer square root number of this number, rounded down. */
/** Returns the integer square root number, rounded down. */
sqrt(): Integer {

@@ -250,2 +250,3 @@ const n = IntegerFn();

/** Returns the truncated integer part of the nth root */
nthRoot(nth: number): Integer {

@@ -258,2 +259,3 @@ const n = IntegerFn();

/** Returns the factorial */
factorial(): Integer {

@@ -269,2 +271,3 @@ if (gmp.mpz_fits_ulong_p(this.mpz_t) === 0) {

/** Returns the double factorial */
doubleFactorial(): Integer {

@@ -280,3 +283,4 @@ if (gmp.mpz_fits_ulong_p(this.mpz_t) === 0) {

isPrime(reps: number = 20): boolean | 'probably-prime' {
/** Determines whether a number is prime using some trial divisions, then reps Miller-Rabin probabilistic primality tests. */
isProbablyPrime(reps: number = 20): boolean | 'probably-prime' {
assertUint32(reps);

@@ -289,2 +293,3 @@ const ret = gmp.mpz_probab_prime_p(this.mpz_t, reps);

/** Identifies primes using a probabilistic algorithm; the chance of a composite passing will be extremely small. */
nextPrime(): Integer {

@@ -311,2 +316,3 @@ const n = IntegerFn();

/** Returns the least common multiple of this number and the given one. */
lcm(val: Integer | number): Integer {

@@ -326,2 +332,3 @@ const n = IntegerFn();

/** Returns the one's complement. */
complement1(): Integer {

@@ -333,2 +340,3 @@ const n = IntegerFn();

/** Returns the two's complement. */
complement2(): Integer {

@@ -463,3 +471,3 @@ const n = IntegerFn();

// Returns the position of the most significant bit. The least significant bit is number 0.
msbPosition() {
msbPosition(): number {
return gmp.mpz_sizeinbase(this.mpz_t, 2) - 1;

@@ -493,3 +501,3 @@ },

/** Creates new integer with the copy of binary representation of num to position offset. Optionally bitCount can be used to zero-pad the number to a specific number of bits. The least significant bit is number 0 */
writeTo(num: Integer, offset = 0, bitCount?: number) {
writeTo(num: Integer, offset = 0, bitCount?: number): Integer {
assertUint32(offset);

@@ -513,2 +521,3 @@ if (!isInteger(num)) throw new Error('Only Integers are supported');

/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean {

@@ -518,2 +527,3 @@ return compare(this.mpz_t, val) === 0;

/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean {

@@ -523,2 +533,3 @@ return compare(this.mpz_t, val) < 0;

/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean {

@@ -528,2 +539,3 @@ return compare(this.mpz_t, val) <= 0;

/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean {

@@ -533,2 +545,3 @@ return compare(this.mpz_t, val) > 0;

/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean {

@@ -538,7 +551,9 @@ return compare(this.mpz_t, val) >= 0;

sign() {
return gmp.mpz_sgn(this.mpz_t);
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1 {
return gmp.mpz_sgn(this.mpz_t) as -1 | 0 | 1;
},
toNumber() {
/** Converts current value into a JavaScript number */
toNumber(): number {
if (gmp.mpz_fits_slong_p(this.mpz_t) === 0) {

@@ -562,3 +577,4 @@ return gmp.mpz_get_d(this.mpz_t);

toString(radix: number = 10) {
/** Converts the number to string */
toString(radix: number = 10): string {
if (!Number.isSafeInteger(radix) || radix < 2 || radix > 62) {

@@ -574,2 +590,3 @@ throw new Error('radix must have a value between 2 and 62');

/** Converts the number to a rational number */
toRational(): Rational {

@@ -579,2 +596,3 @@ return ctx.rationalContext.Rational(this);

/** Converts the number to a floating-point number */
toFloat(): Float {

@@ -581,0 +599,0 @@ return ctx.floatContext.Float(this);

@@ -132,2 +132,3 @@ import type { GMPFunctions } from './functions';

/** Returns the inverse of the number. */
invert(): Rational {

@@ -169,2 +170,3 @@ const n = RationalFn(0, 1);

/** Returns true if the current number is equal to the provided number */
isEqual(val: AllTypes): boolean {

@@ -187,2 +189,3 @@ if (typeof val === 'number' || isInteger(val)) {

/** Returns true if the current number is less than the provided number */
lessThan(val: AllTypes): boolean {

@@ -192,2 +195,3 @@ return compare(this.mpq_t, val) < 0;

/** Returns true if the current number is less than or equal to the provided number */
lessOrEqual(val: AllTypes): boolean {

@@ -197,2 +201,3 @@ return compare(this.mpq_t, val) <= 0;

/** Returns true if the current number is greater than the provided number */
greaterThan(val: AllTypes): boolean {

@@ -202,2 +207,3 @@ return compare(this.mpq_t, val) > 0;

/** Returns true if the current number is greater than or equal to the provided number */
greaterOrEqual(val: AllTypes): boolean {

@@ -207,2 +213,3 @@ return compare(this.mpq_t, val) >= 0;

/** Returns the numerator of the number */
numerator(): Integer {

@@ -214,2 +221,3 @@ const n = ctx.intContext.Integer() as Integer;

/** Returns the denominator of the number */
denominator(): Integer {

@@ -221,11 +229,14 @@ const n = ctx.intContext.Integer() as Integer;

sign() {
return gmp.mpq_sgn(this.mpq_t);
/** Returns the sign of the current value (-1 or 0 or 1) */
sign(): -1 | 0 | 1 {
return gmp.mpq_sgn(this.mpq_t) as -1 | 0 | 1;
},
toNumber() {
/** Converts current value to a JavaScript number */
toNumber(): number {
return gmp.mpq_get_d(this.mpq_t);
},
toString() {
/** Converts the number to string */
toString(): string {
const strptr = gmp.mpq_get_str(0, 10, this.mpq_t);

@@ -238,2 +249,3 @@ const endptr = gmp.mem.indexOf(0, strptr);

/** Converts the number to an integer */
toInteger(): Integer {

@@ -243,2 +255,3 @@ return ctx.intContext.Integer(this);

/** Converts the number to a floating-point number */
toFloat(): Float {

@@ -245,0 +258,0 @@ return ctx.floatContext.Float(this);

@@ -413,7 +413,7 @@ import {CalculateTypeWithDestroy, FloatRoundingMode, FloatType, init as initGMP, IntegerType, RationalType} from '../src';

test('exponent2()', () => {
expect(ctx.Float(1).exponent2()).toBe(1);
expect(ctx.Float(0b1000).exponent2()).toBe(4);
expect(ctx.Float(0.375).exponent2()).toBe(-1); // 0.011
expect(ctx.Float(0.1875).exponent2()).toBe(-2); // 0.0011
test('exponent()', () => {
expect(ctx.Float(1).exponent()).toBe(1);
expect(ctx.Float(0b1000).exponent()).toBe(4);
expect(ctx.Float(0.375).exponent()).toBe(-1); // 0.011
expect(ctx.Float(0.1875).exponent()).toBe(-2); // 0.0011
});

@@ -420,0 +420,0 @@

@@ -167,7 +167,7 @@ import { DivMode } from '../src/integer';

test('isPrime()', () => {
expect(ctx.Integer(9).isPrime()).toBe(false);
expect(ctx.Integer(50).isPrime()).toBe(false);
// expect(ctx.Integer('1795265022').isPrime(2)).toBe(true);
expect(ctx.Integer(53).isPrime()).toBe(true);
test('isProbablyPrime()', () => {
expect(ctx.Integer(9).isProbablyPrime()).toBe(false);
expect(ctx.Integer(50).isProbablyPrime()).toBe(false);
// expect(ctx.Integer('1795265022').isProbablyPrime(2)).toBe(true);
expect(ctx.Integer(53).isProbablyPrime()).toBe(true);
});

@@ -174,0 +174,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc