module Data.Floating.Classes where
import Prelude hiding (Floating(..), RealFloat(..), RealFrac(..), Ord(..))
import Data.Ratio
import Data.Poset
data FPClassification = FPInfinite | FPNaN | FPNormal | FPSubNormal | FPZero
deriving (Show, Read, Eq, Enum, Bounded)
class (Fractional a, Poset a) => Roundable a where
toIntegral :: Integral b => a -> Maybe b
ceiling :: a -> a
floor :: a -> a
truncate :: a -> a
round :: a -> a
floor x
| round x == x = x
| otherwise = round $ x fromRational (1%2)
ceiling x
| round x == x = x
| otherwise = round $ x + fromRational (1%2)
truncate x
| x < 0 = ceiling x
| x > 0 = floor x
| otherwise = x
class Fractional a => Floating a where
(**) :: a -> a -> a
sqrt :: a -> a
acos :: a -> a
asin :: a -> a
atan :: a -> a
cos :: a -> a
sin :: a -> a
tan :: a -> a
acosh :: a -> a
asinh :: a -> a
atanh :: a -> a
cosh :: a -> a
sinh :: a -> a
tanh :: a -> a
exp :: a -> a
log :: a -> a
class Floating a => RealFloat a where
fma :: a -> a -> a -> a
copysign :: a -> a -> a
nextafter :: a -> a -> a
atan2 :: a -> a -> a
fmod :: a -> a -> a
frem :: a -> a -> a
fquotRem :: a -> a -> (Int, a)
hypot :: a -> a -> a
cbrt :: a -> a
exp2 :: a -> a
expm1 :: a -> a
log10 :: a -> a
log1p :: a -> a
log2 :: a -> a
logb :: a -> a
erf :: a -> a
erfc :: a -> a
lgamma :: a -> a
tgamma :: a -> a
classify :: a -> FPClassification
infinity :: a
nan :: a
pi :: a
infinity = 1/0
nan = 0/0
pi = 4 * atan 1