Category talk:Wren-gmp: Difference between revisions
Content added Content deleted
(Wrapped 3 more transcendental MPFR functions.) |
(→Source code (Wren): Added some methods to make dealing with negative numbers more convenient.) |
||
Line 208: | Line 208: | ||
foreign tdiv(n, d) // divides one Mpz object by another (rounds towards zero) |
foreign tdiv(n, d) // divides one Mpz object by another (rounds towards zero) |
||
foreign tdivUi(n, d) // divides an Mpz object by a uint (rounds towards zero) |
foreign tdivUi(n, d) // divides an Mpz object by a uint (rounds towards zero) |
||
addSi(op1, op2) { (op2 >= 0) ? addUi(op1, op2) : subUi(op1, -op2) } // op2 is a sint |
|||
subSi(op1, op2) { (op2 >= 0) ? subUi(op1, op2) : addUi(op1, -op2) } // op2 is a sint |
|||
div(n, d) { tdiv(n, d) } // alias for tdiv |
div(n, d) { tdiv(n, d) } // alias for tdiv |
||
divUi(n, d) { tdivUi(n, d) } // alias for tdivUi |
divUi(n, d) { tdivUi(n, d) } // alias for tdivUi |
||
divSi(n, d) { (d >= 0) ? tdivUi(n, d) : tdivUi(n, -d).neg } // d is a sint |
|||
foreign crem(n, d) // sets the remainder after 'cdiv' by another Mpz object |
foreign crem(n, d) // sets the remainder after 'cdiv' by another Mpz object |
||
Line 222: | Line 226: | ||
rem(n, d) { trem(n,d) } // alias for trem |
rem(n, d) { trem(n,d) } // alias for trem |
||
remUi(n,d) { tremUi(n, d) } |
remUi(n, d) { tremUi(n, d) } // alias for tremUi |
||
remSi(n, d) { (d >= 0) ? tremUi(n, d) : tremUi(n, -d) } // d is a sint |
|||
foreign mod(n, d) // sets to n (Mpz) mod d (Mpz) ignoring the sign of d |
foreign mod(n, d) // sets to n (Mpz) mod d (Mpz) ignoring the sign of d |
||
Line 267: | Line 272: | ||
/* Convenience versions of the above methods where the first (or only) argument is 'this'. |
/* Convenience versions of the above methods where the first (or only) argument is 'this'. |
||
Unless otherwise noted, any other argument must either be another Mpz object or a uint. |
Unless otherwise noted, any other argument must either be another Mpz object or a uint. |
||
Other Nums |
Other Nums are converted by GMP to uint. */ |
||
add(op) { (op is Mpz) ? add(this, op) : ((op is Num) ? |
add(op) { (op is Mpz) ? add(this, op) : ((op is Num) ? addSi(this, op) : Mpz.abort_()) } // sint |
||
sub(op) { (op is Mpz) ? sub(this, op) : ((op is Num) ? |
sub(op) { (op is Mpz) ? sub(this, op) : ((op is Num) ? subSi(this, op) : Mpz.abort_()) } // sint |
||
mul(op) { // sint |
|||
mul(op) { |
|||
if (op is Mpz) return mul(this, op) |
if (op is Mpz) return mul(this, op) |
||
if (op is Num) { |
if (op is Num) { |
||
Line 283: | Line 288: | ||
fdiv(d) { (d is Mpz) ? fdiv(this, d) : ((d is Num) ? fdivUi(this, d) : Mpz.abort_()) } |
fdiv(d) { (d is Mpz) ? fdiv(this, d) : ((d is Num) ? fdivUi(this, d) : Mpz.abort_()) } |
||
tdiv(d) { (d is Mpz) ? tdiv(this, d) : ((d is Num) ? tdivUi(this, d) : Mpz.abort_()) } |
tdiv(d) { (d is Mpz) ? tdiv(this, d) : ((d is Num) ? tdivUi(this, d) : Mpz.abort_()) } |
||
div(d) { tdiv(d) |
div(d) { (d is Mpz) ? tdiv(this, d) : ((d is Num) ? divSi (this, d) : Mpz.abort_()) } // sint |
||
crem(d) { (d is Mpz) ? crem(this, d) : ((d is Num) ? cremUi(this, d) : Mpz.abort_()) } |
crem(d) { (d is Mpz) ? crem(this, d) : ((d is Num) ? cremUi(this, d) : Mpz.abort_()) } |
||
frem(d) { (d is Mpz) ? frem(this, d) : ((d is Num) ? fremUi(this, d) : Mpz.abort_()) } |
frem(d) { (d is Mpz) ? frem(this, d) : ((d is Num) ? fremUi(this, d) : Mpz.abort_()) } |
||
trem(d) { (d is Mpz) ? trem(this, d) : ((d is Num) ? tremUi(this, d) : Mpz.abort_()) } |
trem(d) { (d is Mpz) ? trem(this, d) : ((d is Num) ? tremUi(this, d) : Mpz.abort_()) } |
||
rem(d) { trem(d) } // |
rem(d) { (d is Mpz) ? trem(this, d) : ((d is Num) ? remSi (this, d) : Mpz.abort_()) } // sint |
||
mod(d) { (d is Mpz) ? mod (this, d) : ((d is Num) ? modUi (this, d) : Mpz.abort_()) } |
mod(d) { (d is Mpz) ? mod (this, d) : ((d is Num) ? modUi (this, d) : Mpz.abort_()) } |
||
Line 334: | Line 339: | ||
~ { copy().com } |
~ { copy().com } |
||
+(op) { copy().add(op) |
+(op) { copy().add(op) } |
||
-(op) { copy().sub(op) |
-(op) { copy().sub(op) } |
||
*(op) { copy().mul(op) |
*(op) { copy().mul(op) } |
||
/(op) { copy(). |
/(op) { copy().div(op) } |
||
%(op) { copy(). |
%(op) { copy().rem(op) } |
||
<<(b) { copy().lsh(b) |
<<(b) { copy().lsh(b) } |
||
>>(b) { copy().rsh(b) |
>>(b) { copy().rsh(b) } |
||
&(op) { copy().and(op) |
&(op) { copy().and(op) } |
||
|(op) { copy().ior(op) |
|(op) { copy().ior(op) } |
||
^(op) { copy().xor(op) |
^(op) { copy().xor(op) } |
||
/* Methods which may mutate the current instance or simply return it. */ |
/* Methods which may mutate the current instance or simply return it. */ |
||
Line 975: | Line 980: | ||
foreign uiDiv(op1, op2) // divides a uint by an Mpf object |
foreign uiDiv(op1, op2) // divides a uint by an Mpf object |
||
foreign div2(op1, op2) // divides op1 (Mpf) by 2^op2 (uint) |
foreign div2(op1, op2) // divides op1 (Mpf) by 2^op2 (uint) |
||
addSi(op1, op2) { (op2 >= 0) ? addUi(op1, op2) : subUi(op1, -op2) } // op2 is a sint |
|||
subSi(op1, op2) { (op2 >= 0) ? subUi(op1, op2) : addUi(op1, -op2) } // op2 is a sint |
|||
mulSi(op1, op2) { (op2 >= 0) ? mulUi(op1, op2) : mulUi(op1, -op2).neg } // op2 is a sint |
|||
divSi(op1, op2) { (op2 >= 0) ? divUi(op1, op2) : divUi(op1, -op2).neg } // op2 is a sint |
|||
foreign neg(op) // sets to -op (Mpf) |
foreign neg(op) // sets to -op (Mpf) |
||
Line 1,030: | Line 1,040: | ||
foreign zeta(op) // zeta function of op (Mpf) |
foreign zeta(op) // zeta function of op (Mpf) |
||
foreign zetaUi(op) // zeta function of op (uint) |
foreign zetaUi(op) // zeta function of op (uint) |
||
/* As above methods where the first (or only) argument is 'this'. |
/* As above methods where the first (or only) argument is 'this'. |
||
Unless otherwise noted, any other argument must either be another Mpf object or a |
Unless otherwise noted, any other argument must either be another Mpf object or a sint. |
||
Other Nums are converted by GMP to uint. */ |
Other Nums are converted by GMP to uint. */ |
||
add(op) { (op is Mpf) ? add(this, op) : ((op is Num) ? |
add(op) { (op is Mpf) ? add(this, op) : ((op is Num) ? addSi(this, op) : Mpz.abort_()) } |
||
sub(op) { (op is Mpf) ? sub(this, op) : ((op is Num) ? |
sub(op) { (op is Mpf) ? sub(this, op) : ((op is Num) ? subSi(this, op) : Mpz.abort_()) } |
||
mul(op) { (op is Mpf) ? mul(this, op) : ((op is Num) ? |
mul(op) { (op is Mpf) ? mul(this, op) : ((op is Num) ? mulSi(this, op) : Mpz.abort_()) } |
||
mul2(op) { mul2(this, op) } |
mul2(op) { mul2(this, op) } |
||
div(op) { (op is Mpf) ? div(this, op) : ((op is Num) ? |
div(op) { (op is Mpf) ? div(this, op) : ((op is Num) ? divSi(this, op) : Mpz.abort_()) } |
||
div2(op) { div2(this, op) } |
div2(op) { div2(this, op) } |
||