Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Nonnegative remainder

 [1/2] from: lmecir:geocities at: 2-Aug-2000 21:15


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

 [2/2] from: joel:neely:fedex at: 2-Aug-2000 15:35


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- [lmecir--geocities--com] wrote: