@phensley/decimal
Advanced tools
Comparing version 0.11.0-alpha.0 to 0.11.1-alpha.0
@@ -7,2 +7,7 @@ import { NumberOperands } from './operands'; | ||
export declare const coerceDecimal: (n: DecimalArg) => Decimal; | ||
export interface DecimalParts { | ||
data: number[]; | ||
sign: number; | ||
exp: number; | ||
} | ||
/** | ||
@@ -17,3 +22,3 @@ * Arbitrary precision decimal type. | ||
protected exp: number; | ||
constructor(num: DecimalArg); | ||
constructor(num: DecimalArg | DecimalParts); | ||
/** | ||
@@ -91,2 +96,7 @@ * Compare decimal u to v, returning the following: | ||
/** | ||
* Return a scientific representation of the number, | ||
* Decimal coefficient and adjusted exponent. | ||
*/ | ||
scientific(minIntDigits?: number): [Decimal, number]; | ||
/** | ||
* Number of digits in the unscaled value. | ||
@@ -93,0 +103,0 @@ */ |
@@ -56,3 +56,3 @@ import { add, divide, multiply, subtract, trimLeadingZeros, DivMod } from './math'; | ||
} | ||
else { | ||
else if (num instanceof Decimal) { | ||
this.data = num.data.slice(); | ||
@@ -62,2 +62,7 @@ this.sign = num.sign; | ||
} | ||
else { | ||
this.data = num.data; | ||
this.sign = num.sign; | ||
this.exp = num.exp; | ||
} | ||
} | ||
@@ -328,2 +333,21 @@ /** | ||
/** | ||
* Return a scientific representation of the number, | ||
* Decimal coefficient and adjusted exponent. | ||
*/ | ||
Decimal.prototype.scientific = function (minIntDigits) { | ||
if (minIntDigits === void 0) { minIntDigits = 1; } | ||
minIntDigits = minIntDigits <= 1 ? 1 : minIntDigits; | ||
var exp = -(this.precision() - 1) + (minIntDigits - 1); | ||
var coeff = new Decimal({ | ||
data: this.data, | ||
sign: this.sign, | ||
// removed signed-ness from zero | ||
exp: exp === 0 ? 0 : exp | ||
}); | ||
return [ | ||
coeff, | ||
this.exp - coeff.exp | ||
]; | ||
}; | ||
/** | ||
* Number of digits in the unscaled value. | ||
@@ -600,4 +624,4 @@ */ | ||
Decimal.prototype._shiftright = function (shift, mode) { | ||
var _a, _b, _c; | ||
if (mode === void 0) { mode = 'half-even'; } | ||
var _a, _b, _c; | ||
if (shift <= 0) { | ||
@@ -604,0 +628,0 @@ return; |
@@ -50,2 +50,2 @@ /** | ||
*/ | ||
export declare const divword: (d: number[], n: number, div: number) => number[]; | ||
export declare const divword: (_d: number[], n: number, div: number) => number[]; |
@@ -285,3 +285,3 @@ import { POWERS10 } from './types'; | ||
*/ | ||
export var divword = function (d, n, div) { | ||
export var divword = function (_d, n, div) { | ||
var q = (n / div) | 0; | ||
@@ -288,0 +288,0 @@ var r = n - q * div; |
@@ -7,2 +7,7 @@ import { NumberOperands } from './operands'; | ||
export declare const coerceDecimal: (n: DecimalArg) => Decimal; | ||
export interface DecimalParts { | ||
data: number[]; | ||
sign: number; | ||
exp: number; | ||
} | ||
/** | ||
@@ -17,3 +22,3 @@ * Arbitrary precision decimal type. | ||
protected exp: number; | ||
constructor(num: DecimalArg); | ||
constructor(num: DecimalArg | DecimalParts); | ||
/** | ||
@@ -91,2 +96,7 @@ * Compare decimal u to v, returning the following: | ||
/** | ||
* Return a scientific representation of the number, | ||
* Decimal coefficient and adjusted exponent. | ||
*/ | ||
scientific(minIntDigits?: number): [Decimal, number]; | ||
/** | ||
* Number of digits in the unscaled value. | ||
@@ -93,0 +103,0 @@ */ |
@@ -58,3 +58,3 @@ "use strict"; | ||
} | ||
else { | ||
else if (num instanceof Decimal) { | ||
this.data = num.data.slice(); | ||
@@ -64,2 +64,7 @@ this.sign = num.sign; | ||
} | ||
else { | ||
this.data = num.data; | ||
this.sign = num.sign; | ||
this.exp = num.exp; | ||
} | ||
} | ||
@@ -330,2 +335,21 @@ /** | ||
/** | ||
* Return a scientific representation of the number, | ||
* Decimal coefficient and adjusted exponent. | ||
*/ | ||
Decimal.prototype.scientific = function (minIntDigits) { | ||
if (minIntDigits === void 0) { minIntDigits = 1; } | ||
minIntDigits = minIntDigits <= 1 ? 1 : minIntDigits; | ||
var exp = -(this.precision() - 1) + (minIntDigits - 1); | ||
var coeff = new Decimal({ | ||
data: this.data, | ||
sign: this.sign, | ||
// removed signed-ness from zero | ||
exp: exp === 0 ? 0 : exp | ||
}); | ||
return [ | ||
coeff, | ||
this.exp - coeff.exp | ||
]; | ||
}; | ||
/** | ||
* Number of digits in the unscaled value. | ||
@@ -602,4 +626,4 @@ */ | ||
Decimal.prototype._shiftright = function (shift, mode) { | ||
var _a, _b, _c; | ||
if (mode === void 0) { mode = 'half-even'; } | ||
var _a, _b, _c; | ||
if (shift <= 0) { | ||
@@ -606,0 +630,0 @@ return; |
@@ -50,2 +50,2 @@ /** | ||
*/ | ||
export declare const divword: (d: number[], n: number, div: number) => number[]; | ||
export declare const divword: (_d: number[], n: number, div: number) => number[]; |
@@ -287,3 +287,3 @@ "use strict"; | ||
*/ | ||
exports.divword = function (d, n, div) { | ||
exports.divword = function (_d, n, div) { | ||
var q = (n / div) | 0; | ||
@@ -290,0 +290,0 @@ var r = n - q * div; |
{ | ||
"name": "@phensley/decimal", | ||
"version": "0.11.0-alpha.0", | ||
"version": "0.11.1-alpha.0", | ||
"description": "Arbitrary precision decimal math", | ||
@@ -21,9 +21,9 @@ "main": "lib/index.js", | ||
"build": "yarn build:cj && yarn build:es", | ||
"build:cj": "tsc -p ./tsconfig.build.json", | ||
"build:es": "tsc -p ./tsconfig.build.json --module esnext --outDir lib-es", | ||
"build:watch": "tsc -p ./tsconfig.build.json -w --preserveWatchOutput", | ||
"build:cj": "tsc -p ./tsconfig.json", | ||
"build:es": "tsc -p ./tsconfig.json --module esnext --outDir lib-es", | ||
"build:watch": "tsc -p ./tsconfig.json -w --preserveWatchOutput", | ||
"clean": "rimraf ./lib ./lib-es ./.scratch", | ||
"clean:full": "yarn clean && rimraf ./node_modules", | ||
"coverage": "jest --coverage --runInBand --no-cache --coverageReporters=html", | ||
"lint": "tslint -p ./tsconfig.json", | ||
"lint": "tslint -p ./tsconfig.lint.json", | ||
"prepublish": "yarn build", | ||
@@ -62,3 +62,3 @@ "test:watch": "jest --watch --coverage --coverageReporters=html" | ||
}, | ||
"gitHead": "6028ef476aa9d9570d9ec52bdf53138341fcd8df" | ||
"gitHead": "13828e2aa75ca7640d5e4bdef6b42d6723addd6f" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
228706
3965