Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Jan 25, 2025
1 parent a92e977 commit 3ac46c3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 86 deletions.
84 changes: 41 additions & 43 deletions build/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,47 @@ function ellipticNome( m ) {

}

function am( x, m ) {

if ( m > 1 || isComplex(x) || isComplex(m) ) {

if ( !isComplex(x) ) x = complex(x);
if ( !isComplex(m) ) m = complex(m);

if ( m.im === 0 && m.re <= 1 ) {

var K = ellipticK( m.re );
var n = Math.round( x.re / 2 / K );
x = sub( x, 2 * n * K );

if ( m.re < 0 ) {

var Kp = ellipticK( 1 - m.re );
var p = Math.round( x.im / 2 / Kp.re );

// bitwise test for odd integer
if ( p & 1 ) return sub( n * pi, arcsin( sn(x,m) ) );

}

return add( arcsin( sn(x,m) ), n * pi );

}

return arcsin( sn(x,m) );

} else {

var K = ellipticK(m);
var n = Math.round( x / 2 / K );
x = x - 2 * n * K;

return Math.asin( sn(x,m) ) + n * pi;

}

}

// Jacobi theta functions grow very quickly in imaginary direction
// evaluating elliptic functions without reduction fails accordingly

Expand All @@ -1164,7 +1205,6 @@ function fundamentalParallelogram( x, p1, p2 ) {

}


function sn( x, m ) {

if ( m > 1 || isComplex(x) || isComplex(m) ) {
Expand Down Expand Up @@ -1278,47 +1318,6 @@ function dn( x, m ) {

}

function am( x, m ) {

if ( m > 1 || isComplex(x) || isComplex(m) ) {

if ( !isComplex(x) ) x = complex(x);
if ( !isComplex(m) ) m = complex(m);

if ( m.im === 0 && m.re <= 1 ) {

var K = ellipticK( m.re );
var n = Math.round( x.re / 2 / K );
x = sub( x, 2 * n * K );

if ( m.re < 0 ) {

var Kp = ellipticK( 1 - m.re );
var p = Math.round( x.im / 2 / Kp.re );

// bitwise test for odd integer
if ( p & 1 ) return sub( n * pi, arcsin( sn(x,m) ) );

}

return add( arcsin( sn(x,m) ), n * pi );

}

return arcsin( sn(x,m) );

} else {

var K = ellipticK(m);
var n = Math.round( x / 2 / K );
x = x - 2 * n * K;

return Math.asin( sn(x,m) ) + n * pi;

}

}

function ns( x, m ) { return inv( sn(x,m) ); }

function nc( x, m ) { return inv( cn(x,m) ); }
Expand All @@ -1338,7 +1337,6 @@ function cd( x, m ) { return div( cn(x,m), dn(x,m) ); }
function dc( x, m ) { return div( dn(x,m), cn(x,m) ); }



function weierstrassRoots( g2, g3 ) {

function cubicTrigSolution( p, q, n ) {
Expand Down
84 changes: 41 additions & 43 deletions src/functions/elliptic-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,47 @@ function ellipticNome( m ) {

}

function am( x, m ) {

if ( m > 1 || isComplex(x) || isComplex(m) ) {

if ( !isComplex(x) ) x = complex(x);
if ( !isComplex(m) ) m = complex(m);

if ( m.im === 0 && m.re <= 1 ) {

var K = ellipticK( m.re );
var n = Math.round( x.re / 2 / K );
x = sub( x, 2 * n * K );

if ( m.re < 0 ) {

var Kp = ellipticK( 1 - m.re );
var p = Math.round( x.im / 2 / Kp.re );

// bitwise test for odd integer
if ( p & 1 ) return sub( n * pi, arcsin( sn(x,m) ) );

}

return add( arcsin( sn(x,m) ), n * pi );

}

return arcsin( sn(x,m) );

} else {

var K = ellipticK(m);
var n = Math.round( x / 2 / K );
x = x - 2 * n * K;

return Math.asin( sn(x,m) ) + n * pi;

}

}

// Jacobi theta functions grow very quickly in imaginary direction
// evaluating elliptic functions without reduction fails accordingly

Expand All @@ -208,7 +249,6 @@ function fundamentalParallelogram( x, p1, p2 ) {

}


function sn( x, m ) {

if ( m > 1 || isComplex(x) || isComplex(m) ) {
Expand Down Expand Up @@ -322,47 +362,6 @@ function dn( x, m ) {

}

function am( x, m ) {

if ( m > 1 || isComplex(x) || isComplex(m) ) {

if ( !isComplex(x) ) x = complex(x);
if ( !isComplex(m) ) m = complex(m);

if ( m.im === 0 && m.re <= 1 ) {

var K = ellipticK( m.re );
var n = Math.round( x.re / 2 / K );
x = sub( x, 2 * n * K );

if ( m.re < 0 ) {

var Kp = ellipticK( 1 - m.re );
var p = Math.round( x.im / 2 / Kp.re );

// bitwise test for odd integer
if ( p & 1 ) return sub( n * pi, arcsin( sn(x,m) ) );

}

return add( arcsin( sn(x,m) ), n * pi );

}

return arcsin( sn(x,m) );

} else {

var K = ellipticK(m);
var n = Math.round( x / 2 / K );
x = x - 2 * n * K;

return Math.asin( sn(x,m) ) + n * pi;

}

}

function ns( x, m ) { return inv( sn(x,m) ); }

function nc( x, m ) { return inv( cn(x,m) ); }
Expand All @@ -382,7 +381,6 @@ function cd( x, m ) { return div( cn(x,m), dn(x,m) ); }
function dc( x, m ) { return div( dn(x,m), cn(x,m) ); }



function weierstrassRoots( g2, g3 ) {

function cubicTrigSolution( p, q, n ) {
Expand Down

0 comments on commit 3ac46c3

Please sign in to comment.