Copyright | (C) 2012-2014 Edward Kmett Daniel Peebles (C) 2013-2018 Claude Heiland-Allen |
---|---|
License | LGPL |
Maintainer | Claude Heiland-Allen <claude@mathr.co.uk> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
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 Source #
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 Source #
Construct a properly rounded floating point number from an Int
.
fromDouble :: (Rounding r, Precision p) => Double -> Rounded r p Source #
Construct a rounded floating point number directly from a Double
.
fromLongDouble :: (Rounding r, Precision p) => LongDouble -> Rounded r p Source #
Construct a rounded floating point number directly from a LongDouble
.
toDouble :: (Rounding r, Precision p) => Rounded r p -> Double Source #
Round to Double
with the given rounding mode.
toLongDouble :: (Rounding r, Precision p) => Rounded r p -> LongDouble Source #
Round to LongDouble
with the given rounding mode.
precRound :: (Rounding r, Precision p1, Precision p2) => Rounded r p1 -> Rounded r p2 Source #
Round to a different precision with the given rounding mode.
Precision
class Precision p where Source #
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) Source # | |
Defined in Numeric.Rounded.Precision | |
Precision Double Source # | |
Precision Float Source # | |
Precision CFloat Source # | |
Precision CDouble Source # | |
Precision LongDouble Source # | |
Defined in Numeric.Rounded.Precision precision :: proxy LongDouble -> Int Source # | |
KnownNat n => Precision (Bytes n :: Type) Source # | |
Rounding
class Rounding (r :: RoundingMode) where Source #
rounding :: Proxy r -> RoundingMode Source #
Instances
Rounding TowardNearestWithTiesAwayFromZero Source # | |
Defined in Numeric.Rounded.Rounding | |
Rounding TowardNearest Source # | |
Defined in Numeric.Rounded.Rounding | |
Rounding TowardZero Source # | |
Defined in Numeric.Rounded.Rounding rounding :: Proxy TowardZero -> RoundingMode Source # | |
Rounding TowardInf Source # | |
Defined in Numeric.Rounded.Rounding | |
Rounding TowardNegInf Source # | |
Defined in Numeric.Rounded.Rounding rounding :: Proxy TowardNegInf -> RoundingMode Source # | |
Rounding AwayFromZero Source # | |
Defined in Numeric.Rounded.Rounding rounding :: Proxy AwayFromZero -> RoundingMode Source # | |
Rounding Faithfully Source # | |
Defined in Numeric.Rounded.Rounding rounding :: Proxy Faithfully -> RoundingMode Source # |
data RoundingMode Source #
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 Source #
Useful Constants
Combinators that are oblivious to precision
Mixed-precision operations
(!+!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 6 Source #
(!-!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 6 Source #
(!*!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 7 Source #
(!/!) :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 infixl 7 Source #
min_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 Source #
max_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 Source #
atan2_ :: (Rounding r, Precision p1, Precision p2, Precision p3) => Rounded r p1 -> Rounded r p2 -> Rounded r p3 Source #
Foreign Function Interface
withInRounded :: Rounded r p -> (Ptr MPFR -> IO a) -> IO a Source #
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) Source #
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)) Source #
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) Source #
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)) Source #
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) Source #
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)) Source #
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.