-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | variable-precision floating point -- -- Software floating point with type-tagged variable mantissa precision, -- implemented using a strict pair of Integer and Int -- scaled alike to decodeFloat. Version 0.2.1 added a fixed point -- number type. -- -- Instances of the usual numeric type classes are provided, along with -- additional operators (with carefully chosen fixities) to coerce, -- adjust and reify precisions. -- -- The intention with this library is to be relatively simple but still -- useful, refer to the documentation for caveats concerning accuracy and -- assorted ill-behaviour. -- -- Usage with ghc(i)-7.0.4 might require -fcontext-stack=100. @package variable-precision @version 0.2.1 -- | Boilerplate definitions generated by: -- --
-- flip mapM_ [16..53] $ \p -> let s = show p in -- putStrLn $ "type N" ++ s ++ " = SuccessorTo N" ++ show (p - 1) ++ -- " ; n" ++ s ++ " :: N" ++ s ++ " ; n" ++ s ++ " = undefined" --module TypeLevel.NaturalNumber.ExtraNumbers type N16 = SuccessorTo N15 n16 :: N16 type N17 = SuccessorTo N16 n17 :: N17 type N18 = SuccessorTo N17 n18 :: N18 type N19 = SuccessorTo N18 n19 :: N19 type N20 = SuccessorTo N19 n20 :: N20 type N21 = SuccessorTo N20 n21 :: N21 type N22 = SuccessorTo N21 n22 :: N22 type N23 = SuccessorTo N22 n23 :: N23 type N24 = SuccessorTo N23 n24 :: N24 type N25 = SuccessorTo N24 n25 :: N25 type N26 = SuccessorTo N25 n26 :: N26 type N27 = SuccessorTo N26 n27 :: N27 type N28 = SuccessorTo N27 n28 :: N28 type N29 = SuccessorTo N28 n29 :: N29 type N30 = SuccessorTo N29 n30 :: N30 type N31 = SuccessorTo N30 n31 :: N31 type N32 = SuccessorTo N31 n32 :: N32 type N33 = SuccessorTo N32 n33 :: N33 type N34 = SuccessorTo N33 n34 :: N34 type N35 = SuccessorTo N34 n35 :: N35 type N36 = SuccessorTo N35 n36 :: N36 type N37 = SuccessorTo N36 n37 :: N37 type N38 = SuccessorTo N37 n38 :: N38 type N39 = SuccessorTo N38 n39 :: N39 type N40 = SuccessorTo N39 n40 :: N40 type N41 = SuccessorTo N40 n41 :: N41 type N42 = SuccessorTo N41 n42 :: N42 type N43 = SuccessorTo N42 n43 :: N43 type N44 = SuccessorTo N43 n44 :: N44 type N45 = SuccessorTo N44 n45 :: N45 type N46 = SuccessorTo N45 n46 :: N46 type N47 = SuccessorTo N46 n47 :: N47 type N48 = SuccessorTo N47 n48 :: N48 type N49 = SuccessorTo N48 n49 :: N49 type N50 = SuccessorTo N49 n50 :: N50 type N51 = SuccessorTo N50 n51 :: N51 type N52 = SuccessorTo N51 n52 :: N52 type N53 = SuccessorTo N52 n53 :: N53 -- | Implementations of various floating point algorithms. Accuracy has not -- been extensively verified, and termination has not been proven. -- -- Everything assumes that floatRadix is 2. This is *not* checked. -- -- Functions taking an accuracy parameter may fail to terminate -- if accuracy is too small. Accuracy is measured in least -- significant bits, similarly to '(=~=)'. -- -- In this documentation, basic functionality denotes that methods -- used are from classes: -- -- -- -- Further, basic RealFloat functionality denotes basic -- functionality with the addition of: -- -- -- -- The intention behind the used functionality documentation is to help -- users decide when it is appropriate to use these generic -- implementations to implement instances. module Numeric.VariablePrecision.Algorithms -- | Convert between generic RealFloat types more efficiently than -- realToFrac. Tries hard to preserve special values like -- infinities and negative zero, but any NaN payload is lost. -- -- Uses only basic RealFloat functionality. recodeFloat :: (RealFloat a, RealFloat b) => a -> b -- | Lift a function from Double to generic RealFloat types. viaDouble :: (RealFloat a, RealFloat b) => (Double -> Double) -> a -> b -- | Approximate equality. (a =~= b) c when adding the difference -- to the larger in magnitude changes at most c least -- significant mantissa bits. -- -- Uses only basic RealFloat functionality. (=~=) :: RealFloat a => a -> a -> Int -> Bool -- | Compute a reciprocal using the Newton-Raphson division algorithm, as -- described in -- http://en.wikipedia.org/wiki/Division_%28digital%29#Newton.E2.80.93Raphson_division. -- -- Uses only basic RealFloat functionality. genericRecip :: RealFloat a => Int -> a -> a -- | Compute a square root using Newton's method. -- -- Uses basic RealFloat functionality and '(/)'. genericSqrt :: RealFloat a => Int -> a -> a -- | Compute an exponential using power series. -- -- Uses basic RealFloat functionality, '(/)' and recip. genericExp :: RealFloat a => Int -> a -> a -- | Compute a logarithm. -- -- See genericLog'' for algorithmic references. -- -- Uses basic RealFloat functionality, sqrt and recip. genericLog :: RealFloat a => Int -> a -> a -- | Compute a logarithm using decomposition and a value for log -- 2. -- -- See genericLog'' for algorithmic references. -- -- Uses basic RealFloat functionality, sqrt, and recip. genericLog' :: RealFloat a => Int -> a -> a -> a -- | Compute log 2. -- -- See genericLog'' for algorithmic references. -- -- Uses basic RealFloat functionality, sqrt and recip. genericLog2 :: RealFloat a => Int -> a -- | Compute a logarithm for a value in [0.5,1) using the AGM method as -- described in section 7 of The Logarithmic Constant: log 2 -- Xavier Gourdon and Pascal Sebah, May 18, 2010, -- http://numbers.computation.free.fr/Constants/Log2/log2.ps. -- -- The precondition is not checked. -- -- Uses basic RealFloat functionality, sqrt, and recip. genericLog'' :: RealFloat a => Int -> a -> a -- | Compute pi using the method described in section 8 of -- Multiple-precision zero-finding methods and the complexity of -- elementary function evaluation Richard P Brent, 1975 (revised May -- 30, 2010), http://arxiv.org/abs/1004.3412. -- -- Uses basic RealFloat functionality, '(/)', and sqrt. genericPi :: RealFloat a => Int -> a -- | Special values implemented using basic RealFloat functionality. genericPositiveZero, genericNotANumber, genericNegativeInfinity, genericPositiveInfinity, genericNegativeZero :: RealFloat a => a -- | Check if two numbers have the same sign. May give a nonsense result if -- an argument is NaN. sameSign :: (Ord a, Num a) => a -> a -> Bool -- | Classes for types with precision represented by a type-level natural -- number, and variable precision types. -- -- Note that performance may be (even) slow(er) with some versions of the -- type-level-natural-number package. module Numeric.VariablePrecision.Precision -- | A class for types with precision. The methods must not evaluate their -- arguments, and their results must not be evaluated. Minimal complete -- definition: (none). class HasPrecision t where precisionOf _ = undefined precisionOf :: (HasPrecision t, NaturalNumber p) => t p -> p -- | Much like naturalNumberAsInt combined with precisionOf. precision :: (NaturalNumber p, HasPrecision t) => t p -> Word -- | Much like const with a restricted type. atPrecision :: (NaturalNumber p, HasPrecision t) => t p -> p -> t p -- | Much like const with a restricted type. Precedence between -- < and +. atPrecisionOf :: (HasPrecision t, HasPrecision s) => t p -> s p -> t p -- | An alias for atPrecisionOf. Precedence between < and -- +. (.@) :: (HasPrecision t, HasPrecision s) => t p -> s p -> t p -- | A class for types with adjustable precision. Minimal complete -- definition: adjustPrecision. class HasPrecision t => VariablePrecision t adjustPrecision :: (VariablePrecision t, NaturalNumber p, NaturalNumber q) => t p -> t q -- | Synonym for adjustPrecision. auto :: (VariablePrecision t, NaturalNumber p, NaturalNumber q) => t p -> t q -- | Much like adjustPrecision combined with atPrecision. withPrecision :: (NaturalNumber p, NaturalNumber q, VariablePrecision t) => t p -> q -> t q -- | Much like withPrecision combined with precisionOf. -- Precedence between < and +. withPrecisionOf :: (NaturalNumber p, NaturalNumber q, VariablePrecision t, HasPrecision s) => t p -> s q -> t q -- | An alias for withPrecisionOf. Precedence between < -- and +. (.@~) :: (NaturalNumber p, NaturalNumber q, VariablePrecision t, HasPrecision s) => t p -> s q -> t q -- | Reify from value-level to type-level using Rank2Types. module Numeric.VariablePrecision.Precision.Reify -- | Reify a precision from value-level to type-level. reifyPrecision :: Word -> (forall p. NaturalNumber p => p -> a) -> a -- | Much like reifyPrecision combined with withPrecision. withReifiedPrecision :: (VariablePrecision t, NaturalNumber p) => t p -> Word -> (forall q. NaturalNumber q => t q -> a) -> a -- | An alias for withReifiedPrecision. (.@$) :: (VariablePrecision t, NaturalNumber p) => t p -> Word -> (forall q. NaturalNumber q => t q -> a) -> a -- | Variable precision software fixed point based on Integer. -- -- Accuracy has not been extensively verified. -- -- Example: -- --
-- reifyPrecision 1000 $ \prec -> -- show $ auto (355 :: VFixed N15) / 113 `atPrecision` prec --module Numeric.VariablePrecision.Fixed -- | A software implementation of fixed point arithmetic, using an -- Integer adjusted to p bits after the binary point. data VFixed p -- | A concrete format suitable for storage or wire transmission. data DFixed DFixed :: !Word -> !Integer -> DFixed dxPrecision :: DFixed -> !Word dxMantissa :: DFixed -> !Integer -- | Freeze a VFixed. toDFixed :: NaturalNumber p => VFixed p -> DFixed -- | Thaw a DFixed. Results in Nothing on precision mismatch. fromDFixed :: NaturalNumber p => DFixed -> Maybe (VFixed p) -- | Thaw a DFixed to its natural precision. withDFixed :: DFixed -> (forall p. NaturalNumber p => VFixed p -> r) -> r instance Typeable1 VFixed instance Typeable DFixed instance Data p => Data (VFixed p) instance Eq DFixed instance Ord DFixed instance Read DFixed instance Show DFixed instance Data DFixed instance NaturalNumber p => RealFrac (VFixed p) instance NaturalNumber p => Real (VFixed p) instance NaturalNumber p => Fractional (VFixed p) instance NaturalNumber p => Num (VFixed p) instance NaturalNumber p => Ord (VFixed p) instance NaturalNumber p => Eq (VFixed p) instance NaturalNumber p => Read (VFixed p) instance NaturalNumber p => Show (VFixed p) instance NaturalNumber p => BinDecode (VFixed p) instance VariablePrecision VFixed instance HasPrecision VFixed -- | Variable precision software floating point based on (Integer, -- Int) as used by decodeFloat. Supports infinities and NaN, -- but not negative zero or denormalization. -- -- Accuracy has not been extensively verified, and termination of -- numerical algorithms has not been proven. module Numeric.VariablePrecision.Float -- | A software implementation of floating point arithmetic, using a strict -- pair of Integer and Int, scaled similarly to -- decodeFloat, along with additional values representing: -- --