clojure中rem和mod的區別 詳見clojure doc

看例子

01 user=> (mod 10 5)
02 0
03  
04 user=> (mod 10 6)
05 4
06  
07 user=> (mod 10 10)
08 0
09  
10 user=> (mod 10 -1)
11 0
12  
13 ;; The mod function is defined as the amount by which a number exceeds the largest integer multiple of the divisor that is not greater than that number.
14 ;; The largest integer multiple of 5 not greater than -2 is 5 * -1 = -5. The amount by which -2 exceeds -5 is 3.
15 ;;
16 user=> (mod -2  5)
17 3



01 ;; rem和mod通常用於求餘數
02 ;; mod的結果不爲負數    此處文檔有誤   當(mod 10 -3)時輸出爲 -2 

07 user=> (mod -10 3)
08 2
09 ;; -10 mod 3 (-12 mod 3 )
10ss user=> (rem -10 3)
11 -1


發佈了34 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章