Skip to content

Commit

Permalink
Arbitrary precision argument
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed May 23, 2023
1 parent 6203607 commit bb4deb9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ function abs( x ) {

function arg( x ) {

if ( isArbitrary(x) ) return ln(x).im;

// adding zero prevents unexpected behavior for -0

if ( isComplex(x) ) return Math.atan2( x.im + 0, x.re + 0 );
Expand Down Expand Up @@ -3463,6 +3465,10 @@ function ln( x ) {
if ( x === 0n || x.re === 0n && x.im === 0n )
throw Error( 'Arbitrary natural logarithm singularity' );

if ( x.re === 0n )
if ( x.im > 0n ) return { re: ln(x.im), im: halfPi };
else return { re: ln(-x.im), im: -halfPi };

// convergence near unit circle problematic
// scale argument radially and subtract scaling
// any number will work, convergence faster further out
Expand Down
4 changes: 4 additions & 0 deletions src/functions/logarithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ function ln( x ) {
if ( x === 0n || x.re === 0n && x.im === 0n )
throw Error( 'Arbitrary natural logarithm singularity' );

if ( x.re === 0n )
if ( x.im > 0n ) return { re: ln(x.im), im: halfPi };
else return { re: ln(-x.im), im: -halfPi };

// convergence near unit circle problematic
// scale argument radially and subtract scaling
// any number will work, convergence faster further out
Expand Down
2 changes: 2 additions & 0 deletions src/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ function abs( x ) {

function arg( x ) {

if ( isArbitrary(x) ) return ln(x).im;

// adding zero prevents unexpected behavior for -0

if ( isComplex(x) ) return Math.atan2( x.im + 0, x.re + 0 );
Expand Down

0 comments on commit bb4deb9

Please sign in to comment.