1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +00:00

#128 Accept + prefix

This commit is contained in:
Michael Mclaughlin 2019-05-08 17:05:12 +01:00
parent f468de8e79
commit 3f9eeb0897
3 changed files with 37 additions and 10 deletions

View File

@ -3,7 +3,7 @@
/* /*
* decimal.js v10.1.1 * decimal.js v10.2.0
* An arbitrary-precision Decimal type for JavaScript. * An arbitrary-precision Decimal type for JavaScript.
* https://github.com/MikeMcl/decimal.js * https://github.com/MikeMcl/decimal.js
* Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com> * Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
@ -4341,10 +4341,12 @@
} }
// Minus sign? // Minus sign?
if (v.charCodeAt(0) === 45) { if ((i = v.charCodeAt(0)) === 45) {
v = v.slice(1); v = v.slice(1);
x.s = -1; x.s = -1;
} else { } else {
// Plus sign?
if (i === 43) v = v.slice(1);
x.s = 1; x.s = 1;
} }
@ -4461,6 +4463,8 @@
* *
* hypot(a, b, ...) = sqrt(a^2 + b^2 + ...) * hypot(a, b, ...) = sqrt(a^2 + b^2 + ...)
* *
* arguments {number|string|Decimal}
*
*/ */
function hypot() { function hypot() {
var i, n, var i, n,
@ -4735,6 +4739,8 @@
* -0 if x is -0, * -0 if x is -0,
* NaN otherwise * NaN otherwise
* *
* x {number|string|Decimal}
*
*/ */
function sign(x) { function sign(x) {
x = new this(x); x = new this(x);

View File

@ -1,5 +1,5 @@
/* /*
* decimal.js v10.1.1 * decimal.js v10.2.0
* An arbitrary-precision Decimal type for JavaScript. * An arbitrary-precision Decimal type for JavaScript.
* https://github.com/MikeMcl/decimal.js * https://github.com/MikeMcl/decimal.js
* Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com> * Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
@ -4337,10 +4337,12 @@ function clone(obj) {
} }
// Minus sign? // Minus sign?
if (v.charCodeAt(0) === 45) { if ((i = v.charCodeAt(0)) === 45) {
v = v.slice(1); v = v.slice(1);
x.s = -1; x.s = -1;
} else { } else {
// Plus sign?
if (i === 43) v = v.slice(1);
x.s = 1; x.s = 1;
} }
@ -4457,6 +4459,8 @@ function floor(x) {
* *
* hypot(a, b, ...) = sqrt(a^2 + b^2 + ...) * hypot(a, b, ...) = sqrt(a^2 + b^2 + ...)
* *
* arguments {number|string|Decimal}
*
*/ */
function hypot() { function hypot() {
var i, n, var i, n,
@ -4731,6 +4735,8 @@ function round(x) {
* -0 if x is -0, * -0 if x is -0,
* NaN otherwise * NaN otherwise
* *
* x {number|string|Decimal}
*
*/ */
function sign(x) { function sign(x) {
x = new this(x); x = new this(x);

View File

@ -124,6 +124,7 @@ T('Decimal', function () {
t('0', '0b0'); t('0', '0b0');
t('0', '0B0'); t('0', '0B0');
t('-5', '-0b101'); t('-5', '-0b101');
t('5', '+0b101');
t('1.5', '0b1.1'); t('1.5', '0b1.1');
t('-1.5', '-0b1.1'); t('-1.5', '-0b1.1');
@ -139,6 +140,7 @@ T('Decimal', function () {
// Octal. // Octal.
t('8', '0o10'); t('8', '0o10');
t('-8.5', '-0O010.4'); t('-8.5', '-0O010.4');
t('8.5', '+0O010.4');
t('-262144.000000059604644775390625', '-0o1000000.00000001'); t('-262144.000000059604644775390625', '-0o1000000.00000001');
t('572315667420.390625', '0o10250053005734.31'); t('572315667420.390625', '0o10250053005734.31');
@ -146,6 +148,7 @@ T('Decimal', function () {
t('1', '0x00001'); t('1', '0x00001');
t('255', '0xff'); t('255', '0xff');
t('-15.5', '-0Xf.8'); t('-15.5', '-0Xf.8');
t('15.5', '+0Xf.8');
t('-16777216.00000000023283064365386962890625', '-0x1000000.00000001'); t('-16777216.00000000023283064365386962890625', '-0x1000000.00000001');
t('325927753012307620476767402981591827744994693483231017778102969592507', '0xc16de7aa5bf90c3755ef4dea45e982b351b6e00cd25a82dcfe0646abb'); t('325927753012307620476767402981591827744994693483231017778102969592507', '0xc16de7aa5bf90c3755ef4dea45e982b351b6e00cd25a82dcfe0646abb');
@ -156,14 +159,18 @@ T('Decimal', function () {
} }
t('NaN', NaN); t('NaN', NaN);
t('NaN', -NaN);
t('NaN', 'NaN'); t('NaN', 'NaN');
t('NaN', '-NaN'); t('NaN', '-NaN');
t('NaN', '+NaN');
tx(function () {new Decimal(' NaN')}, "' NaN'"); tx(function () {new Decimal(' NaN')}, "' NaN'");
tx(function () {new Decimal('NaN ')}, "'NaN '"); tx(function () {new Decimal('NaN ')}, "'NaN '");
tx(function () {new Decimal(' NaN ')}, "' NaN '"); tx(function () {new Decimal(' NaN ')}, "' NaN '");
tx(function () {new Decimal('+NaN')}, "'+NaN'"); tx(function () {new Decimal(' -NaN')}, "' -NaN'");
tx(function () {new Decimal(' +NaN')}, "' +NaN'"); tx(function () {new Decimal(' +NaN')}, "' +NaN'");
tx(function () {new Decimal('-NaN ')}, "'-NaN '");
tx(function () {new Decimal('+NaN ')}, "'+NaN '");
tx(function () {new Decimal('.NaN')}, "'.NaN'"); tx(function () {new Decimal('.NaN')}, "'.NaN'");
tx(function () {new Decimal('NaN.')}, "'NaN.'"); tx(function () {new Decimal('NaN.')}, "'NaN.'");
@ -171,11 +178,12 @@ T('Decimal', function () {
t('-Infinity', -Infinity); t('-Infinity', -Infinity);
t('Infinity', 'Infinity'); t('Infinity', 'Infinity');
t('-Infinity', '-Infinity'); t('-Infinity', '-Infinity');
t('Infinity', '+Infinity');
tx(function () {new Decimal(' Infinity')}, "' Infinity '"); tx(function () {new Decimal(' Infinity')}, "' Infinity '");
tx(function () {new Decimal('Infinity ')}, "'Infinity '"); tx(function () {new Decimal('Infinity ')}, "'Infinity '");
tx(function () {new Decimal(' Infinity ')}, "' Infinity '"); tx(function () {new Decimal(' Infinity ')}, "' Infinity '");
tx(function () {new Decimal('+Infinity')}, "'+Infinity'"); tx(function () {new Decimal(' -Infinity')}, "' -Infinity'");
tx(function () {new Decimal(' +Infinity')}, "' +Infinity'"); tx(function () {new Decimal(' +Infinity')}, "' +Infinity'");
tx(function () {new Decimal('.Infinity')}, "'.Infinity'"); tx(function () {new Decimal('.Infinity')}, "'.Infinity'");
tx(function () {new Decimal('Infinity.')}, "'Infinity.'"); tx(function () {new Decimal('Infinity.')}, "'Infinity.'");
@ -197,7 +205,7 @@ T('Decimal', function () {
tx(function () {new Decimal('0-')}, "'0-'"); tx(function () {new Decimal('0-')}, "'0-'");
tx(function () {new Decimal(' -0')}, "' -0'"); tx(function () {new Decimal(' -0')}, "' -0'");
tx(function () {new Decimal('-0 ')}, "'-0 '"); tx(function () {new Decimal('-0 ')}, "'-0 '");
tx(function () {new Decimal('+0')}, "'+0'"); tx(function () {new Decimal('+0 ')}, "'+0 '");
tx(function () {new Decimal(' +0')}, "' +0'"); tx(function () {new Decimal(' +0')}, "' +0'");
tx(function () {new Decimal(' .0')}, "' .0'"); tx(function () {new Decimal(' .0')}, "' .0'");
tx(function () {new Decimal('0. ')}, "'0. '"); tx(function () {new Decimal('0. ')}, "'0. '");
@ -222,12 +230,16 @@ T('Decimal', function () {
t('0.1', '.1'); t('0.1', '.1');
t('0.1', '.1'); t('0.1', '.1');
t('-0.1', '-.1'); t('-0.1', '-.1');
t('0.1', '+.1');
t('1', '1.'); t('1', '1.');
t('1', '1.0'); t('1', '1.0');
t('-1', '-1.'); t('-1', '-1.');
t('1', '+1.');
t('-1', '-1.0000'); t('-1', '-1.0000');
t('1', '1.0000');
t('1', '1.00000000'); t('1', '1.00000000');
t('-1', '-1.000000000000000000000000'); t('-1', '-1.000000000000000000000000');
t('1', '+1.000000000000000000000000');
tx(function () {new Decimal(' 1')}, "' 1'"); tx(function () {new Decimal(' 1')}, "' 1'");
tx(function () {new Decimal('1 ')}, "'1 '"); tx(function () {new Decimal('1 ')}, "'1 '");
@ -235,8 +247,8 @@ T('Decimal', function () {
tx(function () {new Decimal('1-')}, "'1-'"); tx(function () {new Decimal('1-')}, "'1-'");
tx(function () {new Decimal(' -1')}, "' -1'"); tx(function () {new Decimal(' -1')}, "' -1'");
tx(function () {new Decimal('-1 ')}, "'-1 '"); tx(function () {new Decimal('-1 ')}, "'-1 '");
tx(function () {new Decimal('+1')}, "'+1'");
tx(function () {new Decimal(' +1')}, "' +1'"); tx(function () {new Decimal(' +1')}, "' +1'");
tx(function () {new Decimal('+1 ')}, "'+1'");
tx(function () {new Decimal('.1.')}, "'.1.'"); tx(function () {new Decimal('.1.')}, "'.1.'");
tx(function () {new Decimal('+-1')}, "'+-1'"); tx(function () {new Decimal('+-1')}, "'+-1'");
tx(function () {new Decimal('-+1')}, "'-+1'"); tx(function () {new Decimal('-+1')}, "'-+1'");
@ -262,8 +274,9 @@ T('Decimal', function () {
t('123.456789', 123.456789); t('123.456789', 123.456789);
t('-123.456789', -123.456789); t('-123.456789', -123.456789);
t('123.456789', '123.456789');
t('-123.456789', '-123.456789'); t('-123.456789', '-123.456789');
t('123.456789', '123.456789');
t('123.456789', '+123.456789');
tx(function () {new Decimal(void 0)}, "void 0"); tx(function () {new Decimal(void 0)}, "void 0");
tx(function () {new Decimal('undefined')}, "'undefined'"); tx(function () {new Decimal('undefined')}, "'undefined'");
@ -282,7 +295,9 @@ T('Decimal', function () {
tx(function () {new Decimal('ff')}, "'ff'"); tx(function () {new Decimal('ff')}, "'ff'");
tx(function () {new Decimal('0xg')}, "'oxg'"); tx(function () {new Decimal('0xg')}, "'oxg'");
tx(function () {new Decimal('0Xfi')}, "'0Xfi'"); tx(function () {new Decimal('0Xfi')}, "'0Xfi'");
tx(function () {new Decimal('++45')}, "'++45'");
tx(function () {new Decimal('--45')}, "'--45'"); tx(function () {new Decimal('--45')}, "'--45'");
tx(function () {new Decimal('9.99--')}, "'9.99--'"); tx(function () {new Decimal('9.99--')}, "'9.99--'");
tx(function () {new Decimal('9.99++')}, "'9.99++'");
tx(function () {new Decimal('0 0')}, "'0 0'"); tx(function () {new Decimal('0 0')}, "'0 0'");
}); });