mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2024-10-27 20:34:12 +00:00
#132 Fix possible infinite loop when minE is very low
This commit is contained in:
parent
6e5a599fcc
commit
04c6c6f115
10
decimal.js
10
decimal.js
@ -2628,13 +2628,15 @@
|
||||
*
|
||||
*/
|
||||
function cosine(Ctor, x) {
|
||||
var k, y,
|
||||
len = x.d.length;
|
||||
var k, len, y;
|
||||
|
||||
if (x.isZero()) return x;
|
||||
|
||||
// Argument reduction: cos(4x) = 8*(cos^4(x) - cos^2(x)) + 1
|
||||
// i.e. cos(x) = 8*(cos^4(x/4) - cos^2(x/4)) + 1
|
||||
|
||||
// Estimate the optimum number of times to use the argument reduction.
|
||||
len = x.d.length;
|
||||
if (len < 32) {
|
||||
k = Math.ceil(len / 3);
|
||||
y = (1 / tinyPow(4, k)).toString();
|
||||
@ -3664,7 +3666,9 @@
|
||||
var k,
|
||||
len = x.d.length;
|
||||
|
||||
if (len < 3) return taylorSeries(Ctor, 2, x, x);
|
||||
if (len < 3) {
|
||||
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
||||
}
|
||||
|
||||
// Argument reduction: sin(5x) = 16*sin^5(x) - 20*sin^3(x) + 5*sin(x)
|
||||
// i.e. sin(x) = 16*sin^5(x/5) - 20*sin^3(x/5) + 5*sin(x/5)
|
||||
|
Loading…
Reference in New Issue
Block a user