跳轉到內容

Rebol 程式設計/取模

來自華夏公益教科書,開放的書籍,開放的世界
MODULO a b 

處理錯誤的 MOD 包裝器,就像 REMAINDER 一樣。微不足道的值(與 A 和 B 相比)將四捨五入為零。

MODULO 是一個函式值。

  • a -- (型別:數字 貨幣 時間)
  • b -- 將使用絕對值(型別:數字 貨幣 時間)

(特殊屬性)

[編輯 | 編輯原始碼]
  • 捕獲

原始碼

[編輯 | 編輯原始碼]
modulo: func [
    {Wrapper for MOD that handles errors like REMAINDER. Negligible
^-^-values (compared to A and B) are rounded to zero.} 
    [catch] 
    a [number! money! time!] 
    b [number! money! time!] "Absolute value will be used" 
    /local r
][
    throw-on-error [
        any [number? a b: make a b] 
        r: mod a abs b 
        either any [a - r = a r + b = b] [make r 0] [r]
    ]
]
華夏公益教科書