{- - Copyright (C) 2009 Nick Bowler. - - License BSD2: 2-clause BSD license. See LICENSE for full terms. - This is free software: you are free to change and redistribute it. - There is NO WARRANTY, to the extent permitted by law. -} module Data.Floating.Instances where import qualified Prelude import Prelude hiding (round, floor, ceiling, truncate) import Data.Floating.Classes import Data.Ratio instance Integral a => Roundable (Ratio a) where toIntegral = Just . fst . properFraction round x | abs frac >= 1%2 = int%1 + signum frac | otherwise = int%1 where (int, frac) = properFraction x