floating: Add a new Data.Floating.Types module.
[altfloat.git] / Data / Floating.hs
blob65579c4f3732d0e71750f1d3e26bfc2d495bc8a8
1 {-
2 - Copyright (C) 2009-2010 Nick Bowler.
4 - License BSD2: 2-clause BSD license. See LICENSE for full terms.
5 - This is free software: you are free to change and redistribute it.
6 - There is NO WARRANTY, to the extent permitted by law.
7 -}
9 -- | Top level module for alternative floating point support.
10 module Data.Floating (
11 module Data.Floating.Types,
12 module Data.Floating,
13 ) where
15 import Prelude hiding (RealFloat(..), RealFrac(..), Double, Float)
16 import Data.Floating.Types
17 import Data.Floating.Environment
19 import Control.Monad
21 isInfinite :: PrimFloat a => a -> Bool
22 isInfinite = (== FPInfinite) . classify
24 isNaN :: PrimFloat a => a -> Bool
25 isNaN = (== FPNaN) . classify
27 isNormal :: PrimFloat a => a -> Bool
28 isNormal = (== FPNormal) . classify
30 isSubNormal :: PrimFloat a => a -> Bool
31 isSubNormal = (== FPSubNormal) . classify
33 isFinite :: PrimFloat a => a -> Bool
34 isFinite = not . liftM2 (||) isInfinite isNaN
36 isNegativeZero :: PrimFloat a => a -> Bool
37 isNegativeZero = liftM2 (&&) ((== FPZero) . classify) ((== (-1)) . signum)
39 -- | @fquotRem x y@ computes the remainder and integral quotient upon division
40 -- of x by y. The result is (x-n*y, n), where n is the value x/y rounded to
41 -- the nearest integer.
42 fquotRem :: RealFloat a => a -> a -> (a, a)
43 fquotRem x y = (frem x y, nearbyint (x/y))