ref: cb7ae3b919c7ab22cd6cb6003b6b63a5931a6402
dir: /lib/Data/RealFrac.hs/
module Data.RealFrac(module Data.RealFrac) where
import Prelude()
import Primitives
import Data.Ord
import Data.Fractional
import Data.Integral
import Data.Num
import Data.Real
class (Ord a, Real a, Fractional a) => RealFrac a where
properFraction :: (Integral b) => a -> (b,a)
truncate :: (Integral b) => a -> b
round :: (Integral b) => a -> b
ceiling :: (Integral b) => a -> b
floor :: (Integral b) => a -> b
truncate x = m where (m,_) = properFraction x
round x = let (n,r) = properFraction x
m = if r < 0 then n - 1 else n + 1
s = signum (abs r - 0.5)
in if s < 0 then n
else if s > 0 then m
else if even n then n else m
ceiling x = if r > 0 then n + 1 else n
where (n,r) = properFraction x
floor x = if r < 0 then n - 1 else n
where (n,r) = properFraction x