javascript 使用 Math.exp 获得 Math.sinh 结果

javascript using Math.exp for Math.sinh results

我只是想为 Math.sinh here

编写 polyfil

在java脚本doppio

中编写jvm是必需的

但问题是 java Math.sinh(Double.MIN_VALUE) = 4.9E-324 的结果 而在 javascript 中它是 0 因为我正在使用 polyfil 并且它需要 Math.exp(4.9E-324).

(Math.exp(x) - Math.exp(-x)) / 2;

第一个 java脚本将 4.9E-324 变成 5E-324 其次 Math.exp(4.9E-324) 或 Math.pow(Math.E, 4.9E-324 ) 结果为 1,然后结果为 (1-1)/2,即 0 :) 另外 Number.MIN_VALUE 在 JS 中是 5E-324 等同于 Double.MIN_VALUE.

中的 4.9E-324

有什么方法可以避免 math.exp 或 Math.pow 或处理精度。我看过 bigdecimal 库,它也不起作用 有没有其他方法来处理信号图 注意我必须通过所有边界测试用例!!!

sinh(x)的泰勒展开为x+x^3/3!+x^5/5!+x^7/7!+。 . . .这对 x 的所有值都收敛,但对于接近 0 的 x 收敛最快(并给出最好的结果)。

function mySinh(x) {
    var returning = x,
        xToN = x,
        factorial = 1,
        index = 1,
        nextTerm = 1;
    while ( nextTerm != 0 ) {
        index++;
        factorial *= index;
        index++;
        factorial *= index;
        xToN *= x*x;
        nextTerm = xToN/factorial;
        returning += nextTerm;
    }
    return returning;
}

对于x小于1E-108,nextTerm会立即下溢到0,你会得到x回来。

您从使用泰勒展开式切换到使用根据 Math.exp 的定义可能最终取决于您的测试用例正在查看的内容。