When is the difference between quotRem and divMod useful?

前端 未结 3 1310
猫巷女王i
猫巷女王i 2020-12-02 12:19

From the haskell report:

The quot, rem, div, and mod class methods satisfy these laws if y is non-zero:

(x `quot` y)*y + (x `rem`          


        
3条回答
  •  长情又很酷
    2020-12-02 13:01

    This is not exactly an answer to your question, but in GHC on x86, quotRem on Int will compile down to a single machine instruction, whereas divMod does quite a bit more work. So if you are in a speed-critical section and working on positive numbers only, quotRem is the way to go.

提交回复
热议问题