Re: remainder() is not right

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

> On 5 May 2008 at 5:42, Jeremy Cowgar wrote (maybe snipped):

> I've added mod() to the standard library
> 
> }}}
<eucode>
> global function mod(atom x, atom y)
>     return x - y * floor(x / y)
> end function
> </eucode>
{{{

> 
> The test cases all pass:
> 
> }}}
<eucode>
> test_equal("mod() #1",  3573, mod(-27, 3600))
> test_equal("mod() #2",  3573, mod(-3627, 3600))
> test_equal("mod() #3",   -27, mod(-3627, -3600))
> test_equal("mod() #4", -3573, mod(27, -3600))
> test_equal("mod() #5",     0, mod(10, 2))
> </eucode>
{{{

> 
> Should I add any other tests to test for any strange parameters?
> 

At http://en.wikipedia.org/wiki/Modulo_operation#Performance_issues 
it's mentioned a correlation between mod() of powers of 2 could be 
done as a bitwise AND, but this is too specific. Again, this is more 
a matter how it would "look" in C. Prior to 1990 C "%" operator was 
ambiguous but they make their mind since ISO 1999 C (I think).

Best,
Euler

-- 
_
_| euler f german
_| sete lagoas, mg, brazil
_| efgerman{AT}gmail{DOT}com
_| -----------------------------
_| Reply preferably to the list,
_| or to the address above. Thx!

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

Search



Quick Links

User menu

Not signed in.

Misc Menu