| Maintainer | Ziyang Liu <free@cofree.io> |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
Math.Extras.Double
Description
Arithmetic on doubles. Some functions use more general types than Double.
Synopsis
- positiveInfinity :: Double
- negativeInfinity :: Double
- nan :: Double
- type Tolerance = Double
- fuzzyEq :: Tolerance -> Double -> Double -> Bool
- fuzzyCompare :: Tolerance -> Double -> Double -> Ordering
- (~=) :: Double -> Double -> Bool
- (/~=) :: Double -> Double -> Bool
- data RoundingMode
- roundToInteger :: RoundingMode -> Double -> Integer
- saturatedRound :: forall a. (Bounded a, Integral a) => RoundingMode -> Double -> a
- isFinite :: RealFloat a => a -> Bool
- isInteger :: (Eq a, Num a, RealFloat a) => a -> Bool
- toInt64RawBits :: Double -> Int64
- toWord64RawBits :: Double -> Word64
- fromInt64RawBits :: Int64 -> Double
- fromWord64RawBits :: Int64 -> Double
Constant double values
positiveInfinity :: Double Source #
A constant holding the positive infinity of type Double.
negativeInfinity :: Double Source #
A constant holding the negative infinity of type Double.
Fuzzy comparison
fuzzyEq :: Tolerance -> Double -> Double -> Bool Source #
Returns True if the difference of the two numbers are no more than abs(tolerance).
- All NaNs are fuzzily equal.
- With finite tolerance,
positiveInfinityandnegativeInfinityare fuzzily equal only to themselves. - With
positiveInfinityornegativeInfinitytolerance, all non-NaN values are fuzzily equal. - NaN tolerance behaves the same as zero tolerance.
fuzzyEq tolerance is reflexive and symmetric, but not transitive unless tolerance is
zero, positiveInfinity, negativeInfinity, or NaN.
Rounding
data RoundingMode Source #
Constructors
| Up | Round away from 0 |
| Down | Round towards 0 |
| Ceiling | Round towards positive infinity |
| Floor | Round towards negative infinity |
| HalfUp | Round towards nearest integer; round |
| HalfDown | Round towards nearest integer; round |
| HalfEven | Round towards nearest integer; round towards the even neighbor in case of a tie |
Instances
| Eq RoundingMode Source # | |
Defined in Math.Extras.Double | |
| Ord RoundingMode Source # | |
Defined in Math.Extras.Double Methods compare :: RoundingMode -> RoundingMode -> Ordering # (<) :: RoundingMode -> RoundingMode -> Bool # (<=) :: RoundingMode -> RoundingMode -> Bool # (>) :: RoundingMode -> RoundingMode -> Bool # (>=) :: RoundingMode -> RoundingMode -> Bool # max :: RoundingMode -> RoundingMode -> RoundingMode # min :: RoundingMode -> RoundingMode -> RoundingMode # | |
| Show RoundingMode Source # | |
Defined in Math.Extras.Double Methods showsPrec :: Int -> RoundingMode -> ShowS # show :: RoundingMode -> String # showList :: [RoundingMode] -> ShowS # | |
roundToInteger :: RoundingMode -> Double -> Integer Source #
Round a Double to an Integer using the specified RoundingMode.
saturatedRound :: forall a. (Bounded a, Integral a) => RoundingMode -> Double -> a Source #
Round a Double to an integral number using the specified RoundingMode.
Returns maxBound and minBound in case of overflow and underflow, respectively.
Predicates
isFinite :: RealFloat a => a -> Bool Source #
Returns False for NaN and infinity, and True otherwise.
isInteger :: (Eq a, Num a, RealFloat a) => a -> Bool Source #
Returns True if the input represents an integer.
Conversion
toInt64RawBits :: Double -> Int64 Source #
toWord64RawBits :: Double -> Word64 Source #
fromInt64RawBits :: Int64 -> Double Source #