floating: Add instances for CDouble and CFloat.
[altfloat.git] / Data / Floating.hs
blob6dbd5bc16192eca73fa5a4cb159eb1b61f55efaa
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.Classes,
12 Double, Float,
13 module Data.Floating,
14 toFloating
15 ) where
17 import Prelude hiding (RealFloat(..), RealFrac(..), Double, Float)
18 import Data.Floating.Classes
19 import Data.Floating.Instances
20 import Data.Floating.Types
21 import Data.Floating.Types.Double
22 import Data.Floating.Types.Float
23 import Data.Floating.Environment
24 import Data.Floating.CMath.Instances
26 import Control.Monad
28 isInfinite :: PrimFloat a => a -> Bool
29 isInfinite = (== FPInfinite) . classify
31 isNaN :: PrimFloat a => a -> Bool
32 isNaN = (== FPNaN) . classify
34 isNormal :: PrimFloat a => a -> Bool
35 isNormal = (== FPNormal) . classify
37 isSubNormal :: PrimFloat a => a -> Bool
38 isSubNormal = (== FPSubNormal) . classify
40 isFinite :: PrimFloat a => a -> Bool
41 isFinite = not . liftM2 (||) isInfinite isNaN
43 isNegativeZero :: PrimFloat a => a -> Bool
44 isNegativeZero = liftM2 (&&) ((== FPZero) . classify) ((== (-1)) . signum)
46 -- | @fquotRem x y@ computes the remainder and integral quotient upon division
47 -- of x by y. The result is (x-n*y, n), where n is the value x/y rounded to
48 -- the nearest integer.
49 fquotRem :: RealFloat a => a -> a -> (a, a)
50 fquotRem x y = (frem x y, nearbyint (x/y))