Skip to content

Commit 04c6c6f

Browse files
committed
#132 Fix possible infinite loop when minE is very low
1 parent 6e5a599 commit 04c6c6f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

decimal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,13 +2628,15 @@
26282628
*
26292629
*/
26302630
function cosine(Ctor, x) {
2631-
var k, y,
2632-
len = x.d.length;
2633-
2631+
var k, len, y;
2632+
2633+
if (x.isZero()) return x;
2634+
26342635
// Argument reduction: cos(4x) = 8*(cos^4(x) - cos^2(x)) + 1
26352636
// i.e. cos(x) = 8*(cos^4(x/4) - cos^2(x/4)) + 1
26362637

26372638
// Estimate the optimum number of times to use the argument reduction.
2639+
len = x.d.length;
26382640
if (len < 32) {
26392641
k = Math.ceil(len / 3);
26402642
y = (1 / tinyPow(4, k)).toString();
@@ -3663,8 +3665,10 @@
36633665
function sine(Ctor, x) {
36643666
var k,
36653667
len = x.d.length;
3666-
3667-
if (len < 3) return taylorSeries(Ctor, 2, x, x);
3668+
3669+
if (len < 3) {
3670+
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
3671+
}
36683672

36693673
// Argument reduction: sin(5x) = 16*sin^5(x) - 20*sin^3(x) + 5*sin(x)
36703674
// i.e. sin(x) = 16*sin^5(x/5) - 20*sin^3(x/5) + 5*sin(x/5)

0 commit comments

Comments
 (0)