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
14
decimal.js
14
decimal.js
@ -2628,13 +2628,15 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function cosine(Ctor, x) {
|
function cosine(Ctor, x) {
|
||||||
var k, y,
|
var k, len, y;
|
||||||
len = x.d.length;
|
|
||||||
|
if (x.isZero()) return x;
|
||||||
|
|
||||||
// Argument reduction: cos(4x) = 8*(cos^4(x) - cos^2(x)) + 1
|
// 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
|
// 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.
|
// Estimate the optimum number of times to use the argument reduction.
|
||||||
|
len = x.d.length;
|
||||||
if (len < 32) {
|
if (len < 32) {
|
||||||
k = Math.ceil(len / 3);
|
k = Math.ceil(len / 3);
|
||||||
y = (1 / tinyPow(4, k)).toString();
|
y = (1 / tinyPow(4, k)).toString();
|
||||||
@ -3663,8 +3665,10 @@
|
|||||||
function sine(Ctor, x) {
|
function sine(Ctor, x) {
|
||||||
var k,
|
var k,
|
||||||
len = x.d.length;
|
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)
|
// 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)
|
// 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