From 08263d430552fae0c941bb2c4f3a695bb96349ed Mon Sep 17 00:00:00 2001 From: Jayson Harshbarger Date: Thu, 28 Jan 2016 22:11:59 +0900 Subject: [PATCH] Fix for issue #20 --- decimal.js | 1 + test/modules/cos.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/decimal.js b/decimal.js index f2c44e0..7212261 100644 --- a/decimal.js +++ b/decimal.js @@ -3875,6 +3875,7 @@ pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(HALF); + x = Ctor(x); x.s = 1; if (x.lte(halfPi)) { diff --git a/test/modules/cos.js b/test/modules/cos.js index 5c8405c..ce813d2 100644 --- a/test/modules/cos.js +++ b/test/modules/cos.js @@ -8,6 +8,10 @@ if (typeof T === 'undefined') require('../setup'); Decimal.rounding = rm; T.assertEqual(expected, Decimal.cos(n).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({ @@ -29,6 +33,7 @@ if (typeof T === 'undefined') require('../setup'); t('0.000000065', 18, 4, '0.999999999999997888'); // 0.99999999999999788750000000000074377... t('14044.44444444444', 10, 4, '0.04549771706'); + t('-14044.44444444444', 10, 4, '0.04549771706'); t('5', 8, 5, '0.28366219'); t('6723', 3, 3, '0.999'); t('2.04964', 8, 2, '-0.46075321');