Category talk:Wren-gmp: Difference between revisions

→‎Source code (Wren): Added some methods to make dealing with negative numbers more convenient.
(Wrapped 3 more transcendental MPFR functions.)
(→‎Source code (Wren): Added some methods to make dealing with negative numbers more convenient.)
Line 208:
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)
 
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
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
Line 222 ⟶ 226:
 
rem(n, d) { trem(n,d) } // alias for trem
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
Line 267 ⟶ 272:
/* 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.
Other Nums ('mul' also supports sint) are converted by GMP to uint. */
 
add(op) { (op is Mpz) ? add(this, op) : ((op is Num) ? addUiaddSi(this, op) : Mpz.abort_()) } // sint
sub(op) { (op is Mpz) ? sub(this, op) : ((op is Num) ? subUisubSi(this, op) : Mpz.abort_()) } // sint
mul(op) { // sint
mul(op) {
if (op is Mpz) return mul(this, op)
if (op is Num) {
Line 283 ⟶ 288:
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_()) }
div(d) { (d is Mpz) ? tdiv(this, d) }: //((d aliasis forNum) tdiv? divSi (this, d) : Mpz.abort_()) } // sint
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_()) }
trem(d) { (d is Mpz) ? trem(this, d) : ((d is Num) ? tremUi(this, d) : Mpz.abort_()) }
rem(d) { (d is Mpz) ? trem(this, d) : ((d is Num) ? remSi (this, d) : Mpz.abort_()) } // alias for tremsint
mod(d) { (d is Mpz) ? mod (this, d) : ((d is Num) ? modUi (this, d) : Mpz.abort_()) }
 
Line 334 ⟶ 339:
~ { copy().com }
 
+(op) { copy().add(op) }
-(op) { copy().sub(op) }
*(op) { copy().mul(op) }
/(op) { copy().tdivdiv(op) } // always uses tdiv (or div)
%(op) { copy().tremrem(op) } // always uses trem (or rem)
 
<<(b) { copy().lsh(b) }
>>(b) { copy().rsh(b) }
&(op) { copy().and(op) }
|(op) { copy().ior(op) }
^(op) { copy().xor(op) }
 
/* Methods which may mutate the current instance or simply return it. */
Line 975 ⟶ 980:
foreign uiDiv(op1, op2) // divides a uint by an Mpf object
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)
Line 1,030 ⟶ 1,040:
foreign zeta(op) // zeta function of op (Mpf)
foreign zetaUi(op) // zeta function of op (uint)
 
/* 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 uintsint.
Other Nums are converted by GMP to uint. */
 
add(op) { (op is Mpf) ? add(this, op) : ((op is Num) ? addUiaddSi(this, op) : Mpz.abort_()) }
sub(op) { (op is Mpf) ? sub(this, op) : ((op is Num) ? subUisubSi(this, op) : Mpz.abort_()) }
 
mul(op) { (op is Mpf) ? mul(this, op) : ((op is Num) ? mulUimulSi(this, op) : Mpz.abort_()) }
mul2(op) { mul2(this, op) }
 
div(op) { (op is Mpf) ? div(this, op) : ((op is Num) ? divUidivSi(this, op) : Mpz.abort_()) }
div2(op) { div2(this, op) }
 
9,476

edits