| Copyright | (C) 2012-2014 Edward Kmett Daniel Peebles (C) 2013-2018 Claude Heiland-Allen |
|---|---|
| License | BSD3 |
| Maintainer | Claude Heiland-Allen <claude@mathr.co.uk> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Numeric.Rounded
Contents
Description
Synopsis
- data Rounded (r :: RoundingMode) p
- fromInt :: (Rounding r, Precision p) => Int -> Rounded r p
- fromDouble :: (Rounding r, Precision p) => Double -> Rounded r p
- fromLongDouble :: (Rounding r, Precision p) => LongDouble -> Rounded r p
- toDouble :: (Rounding r, Precision p) => Rounded r p -> Double
- toLongDouble :: (Rounding r, Precision p) => Rounded r p -> LongDouble
- toInteger' :: (Rounding r, Precision p) => Rounded r p -> Integer
- precRound :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- class Precision p where
- data Bytes (n :: Nat)
- reifyPrecision :: Int -> (forall (p :: *). Precision p => Proxy p -> a) -> a
- class Rounding (r :: RoundingMode) where
- rounding :: Proxy r -> RoundingMode
- data RoundingMode
- reifyRounding :: RoundingMode -> (forall s. Rounding s => Proxy s -> r) -> r
- kLog2 :: (Rounding r, Precision p) => Rounded r p
- kEuler :: (Rounding r, Precision p) => Rounded r p
- kCatalan :: (Rounding r, Precision p) => Rounded r p
- (.+.) :: Rounding r => Rounded r p -> Rounded r p -> Rounded r p
- (.-.) :: Rounding r => Rounded r p -> Rounded r p -> Rounded r p
- (.*.) :: Rounding r => Rounded r p -> Rounded r p -> Rounded r p
- abs' :: Rounded r p -> Rounded r p
- negate' :: Rounded r p -> Rounded r p
- decodeFloat' :: Rounded r p -> (Integer, Int)
- succUlp :: Rounded r p -> Rounded r p
- predUlp :: Rounded r p -> Rounded r p
- (!+!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- (!-!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- (!*!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- (!/!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- abs_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- negate_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- compare_ :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Ordering
- (!==!) :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Bool
- (!/=!) :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Bool
- (!>=!) :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Bool
- (!<=!) :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Bool
- (!>!) :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Bool
- (!<!) :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 -> Bool
- min_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- max_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- sqrt_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- exp_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- expm1_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- log_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- log1p_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- sin_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- cos_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- tan_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- asin_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- acos_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- atan_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- atan2_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3
- sinh_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- cosh_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- tanh_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- asinh_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- acosh_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- atanh_ :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- truncate_ :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- round_ :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- ceiling_ :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- floor_ :: (Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2
- withInRounded :: Rounded r p -> (Ptr MPFR -> IO a) -> IO a
- withInOutRounded :: Precision p => Rounded r p -> (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p), a)
- withInOutRounded_ :: Precision p => Rounded r p -> (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p))
- withOutRounded :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p), a)
- withOutRounded_ :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p))
- unsafeWithOutRounded :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p), a)
- unsafeWithOutRounded_ :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p))
- peekRounded :: Rounding r => Ptr MPFR -> (forall (p :: *). Precision p => Rounded r p -> IO a) -> IO a
Floating point numbers with a specified rounding mode and precision
data Rounded (r :: RoundingMode) p #
A properly rounded floating-point number with a given rounding mode and precision.
You can coerce to change rounding modes, but not precision.
Instances
fromInt :: (Rounding r, Precision p) => Int -> Rounded r p #
Construct a properly rounded floating point number from an Int.
fromDouble :: (Rounding r, Precision p) => Double -> Rounded r p #
Construct a rounded floating point number directly from a Double.
fromLongDouble :: (Rounding r, Precision p) => LongDouble -> Rounded r p #
Construct a rounded floating point number directly from a LongDouble.
toDouble :: (Rounding r, Precision p) => Rounded r p -> Double #
Round to Double with the given rounding mode.
toLongDouble :: (Rounding r, Precision p) => Rounded r p -> LongDouble #
Round to LongDouble with the given rounding mode.
precRound :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 #
Round to a different precision with the given rounding mode.
Precision
This class is used to specify the number of bits of precision that are maintained in the
significand of a properly Rounded floating point number.
Instances
| KnownNat n => Precision (n :: Nat) # | |
Defined in Numeric.Rounded.Precision | |
| Precision Double # | |
Defined in Numeric.Rounded.Precision | |
| Precision Float # | |
Defined in Numeric.Rounded.Precision | |
| Precision CFloat # | |
Defined in Numeric.Rounded.Precision | |
| Precision CDouble # | |
Defined in Numeric.Rounded.Precision | |
| Precision LongDouble # | |
Defined in Numeric.Rounded.Precision Methods precision :: proxy LongDouble -> Int # | |
| KnownNat n => Precision (Bytes n :: Type) # | |
Defined in Numeric.Rounded.Precision | |
reifyPrecision :: Int -> (forall (p :: *). Precision p => Proxy p -> a) -> a #
Rounding
class Rounding (r :: RoundingMode) where #
Methods
rounding :: Proxy r -> RoundingMode #
Instances
| Rounding TowardNearestWithTiesAwayFromZero # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy TowardNearestWithTiesAwayFromZero -> RoundingMode # | |
| Rounding TowardNearest # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy TowardNearest -> RoundingMode # | |
| Rounding TowardZero # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy TowardZero -> RoundingMode # | |
| Rounding TowardInf # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy TowardInf -> RoundingMode # | |
| Rounding TowardNegInf # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy TowardNegInf -> RoundingMode # | |
| Rounding AwayFromZero # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy AwayFromZero -> RoundingMode # | |
| Rounding Faithfully # | |
Defined in Numeric.Rounded.Rounding Methods rounding :: Proxy Faithfully -> RoundingMode # | |
data RoundingMode #
Constructors
| TowardNearestWithTiesAwayFromZero | currently unsupported placeholder |
| TowardNearest | roundTiesToEven in IEEE 754-2008 |
| TowardZero | roundTowardZero in IEEE 754-2008 |
| TowardInf | roundTowardPositive in IEEE 754-2008 |
| TowardNegInf | roundTowardNegative in IEEE 754-2008 |
| AwayFromZero | round away from zero |
| Faithfully | currently unsupported placeholder |
Instances
reifyRounding :: RoundingMode -> (forall s. Rounding s => Proxy s -> r) -> r #
Useful Constants
Combinators that are oblivious to precision
decodeFloat' :: Rounded r p -> (Integer, Int) #
Mixed-precision operations
(!+!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 6 #
(!-!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 6 #
(!*!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 7 #
(!/!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 7 #
min_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 #
max_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 #
atan2_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 #
Foreign Function Interface
withInRounded :: Rounded r p -> (Ptr MPFR -> IO a) -> IO a #
Use a value as a constant mpfr_t (attempts to modify it may explode,
changing the precision will explode).
withInOutRounded :: Precision p => Rounded r p -> (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p), a) #
Allocates and initializes a new mpfr_t to the value. If the precision matches after
the action then it is peeked and returned. Otherwise you get Nothing.
withInOutRounded_ :: Precision p => Rounded r p -> (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p)) #
Allocates and initializes a new mpfr_t to the value. If the precision matches after
the action then it is peeked and returned. Otherwise you get Nothing. The result
ot the action is ignored.
withOutRounded :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p), a) #
Allocates and initializes a new mpfr_t, if the precision matches after
the action then it is peeked and returned. Otherwise you get Nothing.
withOutRounded_ :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p)) #
Allocates and initializes a new mpfr_t, if the precision matches after
the action then it is peeked and returned. Otherwise you get Nothing.
The result of the action is ignored.
unsafeWithOutRounded :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p), a) #
Like withOutRounded but with the limbs allocated by GHC, which should be
slightly faster. However, it will crash if MPFR tries to reallocate the
limbs, so the action must not try to change the precision or clear it, etc.
unsafeWithOutRounded_ :: Precision p => (Ptr MPFR -> IO a) -> IO (Maybe (Rounded r p)) #
Like withOutRounded_ but with the limbs allocated by GHC, which should be
slightly faster. However, it will crash if MPFR tries to reallocate the
limbs, so the action must not try to change the precision or clear it, etc.