No longer edit original complex argument.

This commit is contained in:
Favian Contreras 2015-02-19 23:53:28 -08:00
parent f296fa2e55
commit 85c8f8efc0
4 changed files with 40 additions and 27 deletions

View File

@ -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);
}

View File

@ -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)) {

View File

@ -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);
}

View File

@ -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;