1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-09-29 23:10:49 +00:00

Add default value to Decimal constructor

- Adding a default value allows Decimal to be constructed without arguments and not throw an error. Javascript primitives like String and Number can be constructed without an argument and this property is useful when using the type with a library like class-transformer.
- Assign a default value of zero as the decimal with no constructor argument.
This commit is contained in:
Nik Jmaeff 2022-12-24 21:03:48 -08:00
parent 7f01abd83d
commit 5ddbf63040
6 changed files with 6 additions and 6 deletions

2
decimal.d.ts vendored
View File

@ -57,7 +57,7 @@ export declare class Decimal {
readonly e: number;
readonly s: number;
constructor(n: Decimal.Value);
constructor(n?: Decimal.Value);
absoluteValue(): Decimal;
abs(): Decimal;

2
decimal.global.d.ts vendored
View File

@ -78,7 +78,7 @@ export declare class Decimal {
readonly e: number;
readonly s: number;
constructor(n: DecimalValue);
constructor(n?: DecimalValue);
absoluteValue(): Decimal;
abs(): Decimal;

View File

@ -4283,6 +4283,7 @@
*
*/
function Decimal(v) {
if (typeof v === 'undefined') v = 0
var e, i, t,
x = this;

View File

@ -4279,6 +4279,7 @@ function clone(obj) {
*
*/
function Decimal(v) {
if (typeof v === 'undefined') v = 0
var e, i, t,
x = this;

View File

@ -278,7 +278,6 @@ T('Decimal', function () {
t('123.456789', '123.456789');
t('123.456789', '+123.456789');
tx(function () {new Decimal(void 0)}, "void 0");
tx(function () {new Decimal('undefined')}, "'undefined'");
tx(function () {new Decimal(null)}, "null");
tx(function () {new Decimal('null')}, "'null'");

View File

@ -540,7 +540,6 @@ T('integer pow', function () {
t('1.494189395849269188211255039709933309086424259778445906419464942576097148044216376789735318980392750336285644804638743600807550074206128272345650029255016954321611264002141919840462369550905098763723254901675135787504979910497931539962354019230845564318816091666473025536e+126', '-32698949771.110178432792', 12);
t('1.1504940871276742926708823617505372960241390892442547940194260102743306128298973371802547471453755938653944600792141533514422490556963535378521856840746722206160260148176604222079226186281680715577736316488196108040509176925372372483300649927835887344415603493563915019264675154039059770309142781930141352329958156926976e+15', '-8.7358521345995835476', 16);
tx(function () {new Decimal('12.345').pow(void 0)}, ".pow(void 0)");
tx(function () {new Decimal('12.345').pow(null)}, ".pow(null)");
tx(function () {new Decimal('12.345').pow(true)}, ".pow(true)");
tx(function () {new Decimal('12.345').pow(false)}, ".pow(false)");