math:mod

new topic     » topic index » view thread      » older message » newer message

mod:namespace math

public function mod (object x, object y)

Compute the remainder of the division of two objects using
floored division.

Parameters:

dividend : any Euphoria object.
divisor : any Euphoria object.

Returns:

An object, the shape of which depends on dividends and divisors. For two atoms, this is the remainder of dividing dividend by divisor, with divisor's sign.

Comments:

There is a integer N such that dividend = N * divisor + result.

    • The result is non-negative and has lesser magnitude than divisor.** N needs not fit in a Euphoria integer.


The result has the same sign as the dividend. When both arguments have the same sign, mod() and remainder() return the same result.
This differs from remainder() in that when the operands' signs are different this function rounds dividend/divisior away from zero whereas remainder() rounds towards zero.

                   mod 
mod(9,5)        =   4 
mod(9,-5)       =  -1  
mod(-9,5)       =   1 
mod(-9,-5)      =  -4 
Note: if you are using floored division: -9 mod -5 = 1 Also mod is taking the sign of divisor not the dividend.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu