< Rebol Programming

USAGE:

MOD a b 

DESCRIPTION:

Compute a nonnegative remainder of A divided by B.

MOD is a function value.

ARGUMENTS:

  • a -- (Type: number money time)
  • b -- Must be nonzero. (Type: number money time)

(SPECIAL ATTRIBUTES)

  • catch

SOURCE CODE

mod: func [
    "Compute a nonnegative remainder of A divided by B." 
    [catch] 
    a [number! money! time!] 
    b [number! money! time!] "Must be nonzero." 
    /local r
][
    all [negative? r: a // b r: r + b] 
    a: abs a 
    either all [a + r = (a + b) positive? r + r - b] [r - b] [r]
]
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.