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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2025 Robert Eisele
Copyright (c) 2026 Robert Eisele

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,5 @@ npm run test

## Copyright and Licensing

Copyright (c) 2025, [Robert Eisele](https://raw.org/)
Copyright (c) 2026, [Robert Eisele](https://raw.org/)
Licensed under the MIT license.
7 changes: 3 additions & 4 deletions dist/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const parse = function (a, b) {
case 'string':

z['im'] = /* void */
z['re'] = 0;
z['re'] = 0;

const tokens = a.replace(/_/g, '')
.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
Expand Down Expand Up @@ -918,11 +918,10 @@ Complex.prototype = {

const a = 2 * this['re'];
const b = 2 * this['im'];
const d = cosh(a) + Math.cos(b);

return new Complex(
sinh(a) / d,
Math.sin(b) / d);
Math.tanh(a) / (1 + Math.cos(b) / cosh(a)),
Math.tan(b) / (1 + cosh(a) / Math.cos(b)));
},

/**
Expand Down
44 changes: 22 additions & 22 deletions dist/complex.min.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/complex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const parse = function (a, b) {
case 'string':

z['im'] = /* void */
z['re'] = 0;
z['re'] = 0;

const tokens = a.replace(/_/g, '')
.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
Expand Down Expand Up @@ -918,11 +918,10 @@ Complex.prototype = {

const a = 2 * this['re'];
const b = 2 * this['im'];
const d = cosh(a) + Math.cos(b);

return new Complex(
sinh(a) / d,
Math.sin(b) / d);
Math.tanh(a) / (1 + Math.cos(b) / cosh(a)),
Math.tan(b) / (1 + cosh(a) / Math.cos(b)));
},

/**
Expand Down
9 changes: 4 additions & 5 deletions src/complex.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @license Complex.js v2.4.3 11/13/2025
* @license Complex.js v2.4.3 5/21/2026
* https://raw.org/article/complex-numbers-in-javascript/
*
* Copyright (c) 2025, Robert Eisele (https://raw.org/)
* Copyright (c) 2026, Robert Eisele (https://raw.org/)
* Licensed under the MIT license.
**/

Expand Down Expand Up @@ -924,11 +924,10 @@ Complex.prototype = {

const a = 2 * this['re'];
const b = 2 * this['im'];
const d = cosh(a) + Math.cos(b);

return new Complex(
sinh(a) / d,
Math.sin(b) / d);
Math.tanh(a) / (1 + Math.cos(b) / cosh(a)),
Math.tan(b) / (1 + cosh(a) / Math.cos(b)));
},

/**
Expand Down
13 changes: 12 additions & 1 deletion tests/complex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ var functionTests = [{
}, {
set: { re: 1, im: 3 },
fn: "tanh",
expect: "0.7680176472869112 - 0.059168539566050726i"
expect: "0.7680176472869112 - 0.05916853956605073i"
}, {
set: { re: 1, im: 3 },
fn: "inverse",
Expand Down Expand Up @@ -1005,6 +1005,17 @@ describe("Complex Details", function () {
assert.strictEqual(Complex({ re: 0.451, im: 0 }).acosh().im, 1.1029108863861707);
});

it('should calculate the tanh correctly', function () {

var a = new Complex(1, 1).tanh();
var b = new Complex(100, 100).tanh();
var c = new Complex(1000, 1000).tanh();

assert.strictEqual(a.toString(), "1.0839233273386946 + 0.27175258531951174i");
assert.strictEqual(b.toString(), "1");
assert.strictEqual(c.toString(), "1");
});

it('should handle sum', function () {
assert.strictEqual(Complex({ abs: 1, arg: 0 }).add({ abs: 1, arg: Math.PI / 2 }).abs(), Math.SQRT2);
assert.strictEqual(Complex({ abs: 1, arg: 0 }).add({ abs: 1, arg: Math.PI / 2 }).arg(), Math.PI / 4);
Expand Down