[REBOL] Nonnegative remainder Re:

2000-08-02 Thread joel . neely

Hi, Ladislav,

One other possibility (that isn't vulnerable to negatives divisors, as
was the one I posted within the past couple of days) is:

 mod: func [
 "computes true (natural) modulus"
 a [integer!] "dividend"
 b [integer!] "divisor"
 ][
 a // b + (b: abs b) // b
 ]

This is certainly no faster than the one below, but is at least "all
arithmetic"...

-jn-

[EMAIL PROTECTED] wrote:
> 
> Hi,
> 
> does anybody know a simpler way how to compute:
> 
> mod: func [
> {compute a non-negative remainder}
> a [number!]
> b [number!]
> /local r
> ] [
> either negative? r: a // b [
> r + abs b
> ] [r]
> ]
> 
> Regards
> Ladislav




[REBOL] Nonnegative remainder

2000-08-02 Thread lmecir

Hi,

does anybody know a simpler way how to compute:

mod: func [
{compute a non-negative remainder}
a [number!]
b [number!]
/local r
] [
either negative? r: a // b [
r + abs b
] [r]
]

Regards
Ladislav