本文介绍了Haskell中`mod`和`rem`的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Haskell中 mod rem 之间的区别究竟是什么?

What exactly is the difference between mod and rem in Haskell?

两者似乎都有相同的结果

Both seems to give the same results

*Main> mod 2 3
2
*Main> rem 2 3
2
*Main> mod 10 5
0
*Main> rem 10 5
0
*Main> mod 1 0
*** Exception: divide by zero
*Main> rem 1 0
*** Exception: divide by zero
*Main> mod 1 (-1)
0
*Main> rem 1 (-1)
0


推荐答案

当第二个参数是负数时它们不一样:

They're not the same when the second argument is negative:

2 `mod` (-3)  ==  -1
2 `rem` (-3)  ==  2

这篇关于Haskell中`mod`和`rem`的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:05