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.8.2 to 0.9.0

14

dist/types/src/float.d.ts

@@ -14,15 +14,11 @@ import type { GMPFunctions } from './functions';

/** Round to nearest, with ties to even. MPFR_RNDN */
ROUND_TO_NEAREST_TIES_TO_EVEN = 0,
ROUND_NEAREST = 0,
/** Round toward zero. MPFR_RNDZ */
ROUND_TOWARD_ZERO = 1,
ROUND_TO_ZERO = 1,
/** Round toward +Infinity. MPFR_RNDU */
ROUND_TOWARD_INF = 2,
ROUND_UP = 2,
/** Round toward -Infinity. MPFR_RNDD */
ROUND_TOWARD_NEG_INF = 3,
ROUND_DOWN = 3,
/** Round away from zero. MPFR_RNDA */
ROUND_AWAY_FROM_ZERO = 4,
/** Faithful rounding. MPFR_RNDF */
ROUND_FAITHFUL = 5,
/** Round to nearest, with ties away from zero. MPFR_RNDNA */
ROUND_TO_NEAREST_AWAY_FROM_ZERO = -1
ROUND_FROM_ZERO = 4
}

@@ -29,0 +25,0 @@ export interface FloatOptions {

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

export declare function getIntegerContext(gmp: GMPFunctions, ctx: any): {
Integer: (num?: string | number | Integer | Uint8Array, radix?: number) => {
Integer: (num?: string | number | Integer | Uint8Array | Rational | Float, radix?: number) => {
mpz_t: number;

@@ -21,0 +21,0 @@ type: string;

@@ -5,1 +5,2 @@ export declare function isUint32(num: number): boolean;

export declare function assertInt32(num: number): void;
export declare function assertArray(arr: any[]): void;
{
"name": "gmp-wasm",
"version": "0.8.2",
"version": "0.9.0",
"description": "Arbitrary-precision Integer, Rational and Float types based on the GMP and MPFR libraries",

@@ -5,0 +5,0 @@ "main": "dist/index.umd.js",

@@ -20,15 +20,15 @@ import type { GMPFunctions, mpfr_rnd_t } from './functions';

/** Round to nearest, with ties to even. MPFR_RNDN */
ROUND_TO_NEAREST_TIES_TO_EVEN = 0,
ROUND_NEAREST = 0,
/** Round toward zero. MPFR_RNDZ */
ROUND_TOWARD_ZERO = 1,
ROUND_TO_ZERO = 1,
/** Round toward +Infinity. MPFR_RNDU */
ROUND_TOWARD_INF = 2,
ROUND_UP = 2,
/** Round toward -Infinity. MPFR_RNDD */
ROUND_TOWARD_NEG_INF = 3,
ROUND_DOWN = 3,
/** Round away from zero. MPFR_RNDA */
ROUND_AWAY_FROM_ZERO = 4,
/** Faithful rounding. MPFR_RNDF */
ROUND_FAITHFUL = 5,
/** Round to nearest, with ties away from zero. MPFR_RNDNA */
ROUND_TO_NEAREST_AWAY_FROM_ZERO = -1,
ROUND_FROM_ZERO = 4,
// /** (Experimental) Faithful rounding. MPFR_RNDF */
// ROUND_FAITHFUL = 5,
// /** (Experimental) Round to nearest, with ties away from zero. MPFR_RNDNA */
// ROUND_TO_NEAREST_AWAY_FROM_ZERO = -1,
};

@@ -100,3 +100,3 @@

const globalRndMode = (ctxOptions.roundingMode ?? FloatRoundingMode.ROUND_TO_NEAREST_TIES_TO_EVEN) as number as mpfr_rnd_t;
const globalRndMode = (ctxOptions.roundingMode ?? FloatRoundingMode.ROUND_NEAREST) as number as mpfr_rnd_t;
const globalPrecisionBits = ctxOptions.precisionBits ?? 52;

@@ -103,0 +103,0 @@ assertUint32(globalPrecisionBits);

import type { GMPFunctions } from './functions';
import { Float } from './float';
import { Rational } from './rational';
import { assertInt32, assertUint32 } from './util';
import { assertArray, assertInt32, assertUint32 } from './util';

@@ -366,5 +366,3 @@ const decoder = new TextDecoder();

const n = IntegerFn(this);
if (!Array.isArray(indices)){
throw new Array('Requires array!');
}
assertArray(indices);
indices.forEach(i => {

@@ -388,5 +386,3 @@ assertUint32(i);

const n = IntegerFn(this);
if (!Array.isArray(indices)){
throw new Array('Requires array!');
}
assertArray(indices);
indices.forEach(i => {

@@ -410,5 +406,3 @@ assertUint32(i);

const n = IntegerFn(this);
if (!Array.isArray(indices)){
throw new Array('Requires array!');
}
assertArray(indices);
indices.forEach(i => {

@@ -530,3 +524,3 @@ assertUint32(i);

const IntegerFn = (num?: string | number | Integer | Uint8Array, radix: number = 10) => {
const IntegerFn = (num?: string | number | Integer | Uint8Array | Rational | Float, radix: number = 10) => {
const instance = Object.create(IntPrototype) as typeof IntPrototype;

@@ -560,2 +554,7 @@ instance.mpz_t = gmp.mpz_t();

gmp.free(wasmBufPtr);
} else if (isRational(num)) {
const f = ctx.floatContext.Float(num);
gmp.mpfr_get_z(instance.mpz_t, f.mpfr_t, 0);
} else if (isFloat(num)) {
gmp.mpfr_get_z(instance.mpz_t, (num as Float).mpfr_t, (num as Float).rndMode);
} else {

@@ -562,0 +561,0 @@ gmp.mpz_t_free(instance.mpz_t);

@@ -20,1 +20,7 @@ export function isUint32(num: number) {

}
export function assertArray(arr: any[]) {
if (!Array.isArray(arr)) {
throw new Error('Invalid parameter specified. Array is required!');
}
}

@@ -388,3 +388,3 @@ import { CalculateTypeWithDestroy, FloatRoundingMode, init as initGMP } from '../src';

test('FloatOptions', () => {
const roundingMode = FloatRoundingMode.ROUND_TOWARD_NEG_INF;
const roundingMode = FloatRoundingMode.ROUND_DOWN;
const options = { precisionBits: 10, roundingMode };

@@ -403,9 +403,9 @@ expect(gmp.calculate(g => g.Float(1).div(3), {})).toBe('0.33333333333333337');

expect(gmp.calculate(g => g.Float(1).div(g.Float(3)), options)).toBe('0.333');
const { ROUND_TOWARD_INF } = FloatRoundingMode;
expect(gmp.calculate(g => g.Float(1, { roundingMode: ROUND_TOWARD_INF }).div(g.Float(3)), options)).toBe('0.33349');
expect(gmp.calculate(g => g.Float(1).div(g.Float(3, { roundingMode: ROUND_TOWARD_INF })), options)).toBe('0.33301');
const { ROUND_UP } = FloatRoundingMode;
expect(gmp.calculate(g => g.Float(1, { roundingMode: ROUND_UP }).div(g.Float(3)), options)).toBe('0.33349');
expect(gmp.calculate(g => g.Float(1).div(g.Float(3, { roundingMode: ROUND_UP })), options)).toBe('0.33301');
});
test('FloatOptions constants', () => {
const roundingMode = FloatRoundingMode.ROUND_TOWARD_NEG_INF;
const roundingMode = FloatRoundingMode.ROUND_DOWN;
const options = { precisionBits: 10, roundingMode };

@@ -412,0 +412,0 @@ expect(gmp.calculate(g => g.Pi(), options)).toBe('3.1406');

@@ -413,2 +413,18 @@ import { DivMode } from '../src/integer';

test('init from Rational', () => {
compare(ctx.Integer(ctx.Rational(0, 1)), '0');
compare(ctx.Integer(ctx.Rational(-3, 2)), '-2');
compare(ctx.Integer(ctx.Rational(-4, 3)), '-1');
compare(ctx.Integer(ctx.Rational('3/2')), '2');
compare(ctx.Integer(ctx.Rational('4/3')), '1');
});
test('init from Float', () => {
compare(ctx.Integer(ctx.Float('0')), '0');
compare(ctx.Integer(ctx.Float('-1.49')), '-1');
compare(ctx.Integer(ctx.Float('-1.50')), '-2');
compare(ctx.Integer(ctx.Float('1.49')), '1');
compare(ctx.Integer(ctx.Float('1.50')), '2');
});
test('toString()', () => {

@@ -415,0 +431,0 @@ expect(ctx.Integer('2').toString()).toBe('2');

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