Does there exist a difference in functionality between floor and truncate in Haskell?
They seem to perform the same functionality and they have the same type signature:
truncate :: (Integral b, RealFrac a) => a -> bfloor :: (Integral b, RealFrac a) => a -> bYes, for negative numbers. If we read the documentation, we see:
truncate :: Integral b => a -> b
truncate xreturns the integer nearestxbetween zero andx
and:
floor :: Integral b => a -> b
floor xreturns the greatest integer not greater thanx
So if we enter a negative number, like -3.5 we obtain:
Prelude> truncate (-3.5)
-3
Prelude> floor (-3.5)
-4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With