Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ Complex.prototype = {
},

/**
* Calculate the complex coth
* Calculate the complex csch
*
* @returns {Complex}
*/
Expand Down Expand Up @@ -1046,19 +1046,16 @@ Complex.prototype = {
*/
'acosh': function () {

// acosh(c) = log(c + sqrt(c^2 - 1))
// acosh(c) = log(c + sqrt(c - 1) * sqrt(c + 1))

const res = this['acos']();
if (res['im'] <= 0) {
const tmp = res['re'];
res['re'] = -res['im'];
res['im'] = tmp;
} else {
const tmp = res['im'];
res['im'] = -res['re'];
res['re'] = tmp;
}
return res;
const a = this['re'];
const b = this['im'];

const t1 = new Complex(a + 1, b).sqrt();
const t2 = new Complex(a - 1, b).sqrt();
return new Complex(
a + t1['re'] * t2['re'] - t1['im'] * t2['im'],
b + t1['re'] * t2['im'] + t1['im'] * t2['re']).log();
},

/**
Expand Down Expand Up @@ -1137,7 +1134,7 @@ Complex.prototype = {

return new Complex(
(a !== 0)
? Math.log(a + Math.sqrt(a * a + 1))
? Math.log(1 / a + Math.sqrt(1 / (a * a) + 1))
: Infinity, 0);
}

Expand Down
1 change: 1 addition & 0 deletions tests/complex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ describe("Complex Details", function () {

it('should handle get complex part', function () {
assert.strictEqual(Complex({ abs: 1, arg: Math.PI / 4 }).im, 0.7071067811865475);
assert.strictEqual(Complex({ re: 0.451, im: 0 }).acosh().im, 1.1029108863861707);
});

it('should handle sum', function () {
Expand Down