Friday 29 April 2016

Haskell: Difference between rem Vs mod

For rem operator, Sign of the result is same as sign of x. The remainder (rem) and modulus (mod) are defined as follows:
            rem(X,Y) = X –(X/Y)*Y     (in which X/Y in an integer)
            mod(X,Y) = X – Y * N      (in which N is an integer)

*Main> rem 10 (-3)
1
*Main> 
*Main> mod 10 (-3)
-2


For positive integers both mod and rem behave like same.
*Main> rem 10 3
1
*Main> mod 10 3
1


Previous                                                 Next                                                 Home

No comments:

Post a Comment