Skip to content

Commit

Permalink
fix rounding issue when calulating expt to integer number #300
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 11, 2024
1 parent cd4848e commit c742601
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.18.1-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&864bd776940bc8e5e39f39a85177ea2a)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&93d53cb0ea8e3d697ec2cb10cee1490f)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
16 changes: 12 additions & 4 deletions dist/lips.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -5742,7 +5742,15 @@ LComplex.prototype.pow = function(n) {
im: e.mul(Math.sin(p.__im__.valueOf()))
});
}
const positive = n.__re__.cmp(0) > 0;
n = n.__re__.valueOf();
if (LNumber.isInteger(n) && positive) {
let result = this;
while (--n) {
result = result.mul(this);
}
return result;
}
// equation taken from Wikipedia:
// https://w.wiki/97V3#Integer_and_fractional_exponents
const r = magnitude.pow(n);
Expand Down
2 changes: 1 addition & 1 deletion tests/numbers.scm
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@
(t.is (expt 0.5 0.5) 0.7071067811865476)
(t.is (expt 0.5 -0.5) 1.414213562373095)

(t.is (expt 10+10i 2) 1.2246467991473534e-14+200.00000000000003i)
(t.is (expt 10+10i 2) +200i)
(t.is (expt 10+10i 1/2) 3.4743442276011565+1.4391204994250744i)
(t.is (expt 10+10i -1/2) 0.24567323635131155-0.1017611864088041i)
(t.is (expt 10+10i 0.5) 3.4743442276011565+1.4391204994250744i)
Expand Down

0 comments on commit c742601

Please sign in to comment.