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

Merge pull request #21 from Hypercubed/fix/cosine

Bugfix: #20 cos mutates value
This commit is contained in:
Michael M 2016-01-28 22:46:32 +00:00
commit cefd7f5db8
2 changed files with 6 additions and 0 deletions

View File

@ -3875,6 +3875,7 @@
pi = getPi(Ctor, Ctor.precision, 1), pi = getPi(Ctor, Ctor.precision, 1),
halfPi = pi.times(HALF); halfPi = pi.times(HALF);
x = Ctor(x);
x.s = 1; x.s = 1;
if (x.lte(halfPi)) { if (x.lte(halfPi)) {

View File

@ -8,6 +8,10 @@ if (typeof T === 'undefined') require('../setup');
Decimal.rounding = rm; Decimal.rounding = rm;
T.assertEqual(expected, Decimal.cos(n).valueOf()); T.assertEqual(expected, Decimal.cos(n).valueOf());
T.assertEqual(expected, new Decimal(n).cos().valueOf()); T.assertEqual(expected, new Decimal(n).cos().valueOf());
var x = new Decimal(n);
x.cos();
T.assertEqual(new Decimal(n).valueOf(), x.valueOf());
} }
Decimal.config({ Decimal.config({
@ -29,6 +33,7 @@ if (typeof T === 'undefined') require('../setup');
t('0.000000065', 18, 4, '0.999999999999997888'); // 0.99999999999999788750000000000074377... t('0.000000065', 18, 4, '0.999999999999997888'); // 0.99999999999999788750000000000074377...
t('14044.44444444444', 10, 4, '0.04549771706'); t('14044.44444444444', 10, 4, '0.04549771706');
t('-14044.44444444444', 10, 4, '0.04549771706');
t('5', 8, 5, '0.28366219'); t('5', 8, 5, '0.28366219');
t('6723', 3, 3, '0.999'); t('6723', 3, 3, '0.999');
t('2.04964', 8, 2, '-0.46075321'); t('2.04964', 8, 2, '-0.46075321');