Skip to content

Commit

Permalink
Integer & fractional parts
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Jan 19, 2021
1 parent 1058477 commit 742bb86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -2988,6 +2988,16 @@ function sign( x ) {

}

function integerPart( x ) {

if ( isComplex(x) ) return complex( Math.trunc(x.re), Math.trunc(x.im) );

return Math.trunc(x);

}

function fractionalPart( x ) { return sub( x, integerPart(x) ); }


function kronecker( i, j ) {

Expand Down
4 changes: 4 additions & 0 deletions docs/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ <h1>Miscellaneous Functions</h1>

<p><b>sign( <i>x</i> )</b> &mdash; signum function of a real or complex number</p>

<p><b>integerPart( <i>x</i> )</b> &mdash; integer part of a real or complex number</p>

<p><b>fractionalPart( <i>x</i> )</b> &mdash; fractional part of a real or complex number</p>

<p><b>kronecker( <i>i</i>, <i>j</i> )</b> &mdash; Kronecker delta &delta;<sub><i>ij</i></sub> for real or complex arguments</p>

<p><b>kronecker( <i>i</i>, <i>j</i>, <i>k</i>, &hellip; )</b> &mdash; Kronecker delta &delta;<sub><i>ijk&hellip;</i></sub> for an arbitrary number of real or complex arguments</p>
Expand Down
10 changes: 10 additions & 0 deletions src/functions/miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ function sign( x ) {

}

function integerPart( x ) {

if ( isComplex(x) ) return complex( Math.trunc(x.re), Math.trunc(x.im) );

return Math.trunc(x);

}

function fractionalPart( x ) { return sub( x, integerPart(x) ); }


function kronecker( i, j ) {

Expand Down

0 comments on commit 742bb86

Please sign in to comment.