Skip to content

Commit

Permalink
BREAKING(complex/math): remove powCmplx function (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
babiabeo authored Jun 6, 2024
1 parent a88570e commit d200d15
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
deno.lock
docs
docs
package.json
62 changes: 0 additions & 62 deletions src/math/power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,65 +158,3 @@ export function pow(a: complex, nb: number | complex): complex {

return cmplx(r * cos, r * sin);
}

/**
* Raises the complex number to the complex `b`-th power.
*
* @param a The complex number
* @param b The complex `b`-th power
*
* @example
* ```ts
* import { ComplexMath, cmplx } from "@babia/complex";
*
* const i = cmplx(0, 1);
*
* ComplexMath.powCmplx(i, i); // i^i = e^(-pi / 2) = 0.20787957635076193
* ```
*
* @deprecated (will be removed after v1.1.0) Use {@linkcode pow} instead.
*/
export function powCmplx(a: complex, b: complex): complex {
if (a.isZero()) {
if (b.isNaN()) {
return Complex.NaN();
}

const real = b.real;
const imag = b.imag;

if (real === 0) {
return cmplx(1);
}

if (real < 0) {
if (imag === 0) {
return cmplx(POS_INF);
}

return Complex.Inf();
}

return cmplx(0);
}

const modulus = a.abs();
if (modulus === 0) {
return cmplx(0);
}

const arg = a.phase();

let r = Math.pow(modulus, b.real);
let theta = b.real * arg;

if (b.imag) {
r *= Math.exp(-b.imag * arg);
theta += b.imag * Math.log(modulus);
}

const cos = Math.cos(theta);
const sin = Math.sin(theta);

return cmplx(r * cos, r * sin);
}
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export function reducePi(n: number): number {
t += 0.5;
}

const i = Math.trunc(t);
t = i;
t = Math.trunc(t);

return ((n - t * DP1) - t * DP2) - t * DP3;
}

0 comments on commit d200d15

Please sign in to comment.