diff --git a/lib/function/trigonometry/acoth.js b/lib/function/trigonometry/acoth.js index 13efed051..ad25964b8 100644 --- a/lib/function/trigonometry/acoth.js +++ b/lib/function/trigonometry/acoth.js @@ -53,13 +53,15 @@ module.exports = function (math) { // acoth(z) = -i*atanh(1/z) var den = x.re*x.re + x.im*x.im; - if (den != 0) { - x.re = x.re / den; - x.im = -x.im / den; - } else { - x.re = (x.re != 0) ? (x.re / 0) : 0; - x.im = (x.im != 0) ? -(x.im / 0) : 0; - } + x = (den != 0) + ? new Complex( + x.re / den, + -x.im / den + ) + : new Complex( + (x.re != 0) ? (x.re / 0) : 0, + (x.im != 0) ? -(x.im / 0) : 0 + ); return math.atanh(x); } diff --git a/lib/function/trigonometry/acsch.js b/lib/function/trigonometry/acsch.js index 12b545869..0ce66bda7 100644 --- a/lib/function/trigonometry/acsch.js +++ b/lib/function/trigonometry/acsch.js @@ -48,22 +48,26 @@ module.exports = function (math) { } if (isComplex(x)) { + if (x.im == 0) { + x = (x.re != 0) + ? Math.log(x.re + Math.sqrt(x.re*x.re + 1)) + : Infinity; + return new Complex(x, 0); + } + // acsch(z) = -i*asinh(1/z) var den = x.re*x.re + x.im*x.im; - if (den != 0) { - x.re = x.re / den; - x.im = -x.im / den; - } else { - x.re = (x.re != 0) ? (x.re / 0) : 0; - x.im = (x.im != 0) ? -(x.im / 0) : 0; - } + x = (den != 0) + ? new Complex( + x.re / den, + -x.im / den + ) + : new Complex( + (x.re != 0) ? (x.re / 0) : 0, + (x.im != 0) ? -(x.im / 0) : 0 + ); - if (x.im) { - return math.asinh(x); - } - - x = 1 / x.re; - return new Complex(Math.log(x + Math.sqrt(x*x + 1)), 0); + return math.asinh(x); } if (isCollection(x)) { diff --git a/lib/function/trigonometry/asech.js b/lib/function/trigonometry/asech.js index b5a9fefec..b393b9770 100644 --- a/lib/function/trigonometry/asech.js +++ b/lib/function/trigonometry/asech.js @@ -54,13 +54,15 @@ module.exports = function (math) { // acsch(z) = -i*asinh(1/z) var den = x.re*x.re + x.im*x.im; - if (den != 0) { - x.re = x.re / den; - x.im = -x.im / den; - } else { - x.re = (x.re != 0) ? (x.re / 0) : 0; - x.im = (x.im != 0) ? -(x.im / 0) : 0; - } + x = (den != 0) + ? new Complex( + x.re / den, + -x.im / den + ) + : new Complex( + (x.re != 0) ? (x.re / 0) : 0, + (x.im != 0) ? -(x.im / 0) : 0 + ); return math.acosh(x); } diff --git a/lib/function/trigonometry/asinh.js b/lib/function/trigonometry/asinh.js index 0313f02ee..9393b6657 100644 --- a/lib/function/trigonometry/asinh.js +++ b/lib/function/trigonometry/asinh.js @@ -53,6 +53,11 @@ module.exports = function (math) { x.re = temp; var asin = math.asin(x); + + // restore original values + x.re = -x.im; + x.im = temp; + temp = asin.re; asin.re = -asin.im; asin.im = temp;