packages feed

numeric-limits (empty) → 0.1.0.0

raw patch · 3 files changed

+78/−0 lines, 3 filesdep +basesetup-changed

Dependencies added: base

Files

+ Numeric/Limits.hs view
@@ -0,0 +1,61 @@+-- | Various floating point limit related numerical constants.+module Numeric.Limits(+    -- * Significant digits+    digits10,+    -- * Minimum difference+    epsilon,+    -- * Extreme finite values+    maxValue,+    minValue,+    -- * Abnormal values+    infinity,+    nan,+    ) where++-- | The number of decimal digits that the type can represent without loss of precision.+{-# SPECIALIZE digits10 :: Double -> Int #-}+{-# SPECIALIZE digits10 :: Float -> Int #-}+digits10 :: (RealFloat a) => a -> Int+digits10 x = count 0 (floatRadix x ^ floatDigits x)+  where count n v = if v < 10 then n else count (n+1) (v `quot` 10)+    ++-- | The difference between 1 and the smallest value greater than 1 that is representable for the type.+{-# SPECIALIZE epsilon :: Double #-}+{-# SPECIALIZE epsilon :: Float #-}+epsilon :: (RealFloat a) => a+epsilon = r+  where r = 1 - encodeFloat (m-1) e+        (m, e) = decodeFloat (1 `asTypeOf` r)++-- | Infinity value if the type supports it.+{-# SPECIALIZE infinity :: Double #-}+{-# SPECIALIZE infinity :: Float #-}+infinity :: (RealFloat a) => a+infinity = 1/0++-- | Not-a-number value if the type supports it.+{-# SPECIALIZE nan :: Double #-}+{-# SPECIALIZE nan :: Float #-}+nan :: (RealFloat a) => a+nan = 0/0++-- | The maximum finite value for the type.+{-# SPECIALIZE maxValue :: Double #-}+{-# SPECIALIZE maxValue :: Float #-}+maxValue :: (RealFloat a) => a+maxValue = x+  where n = floatDigits x+        b = floatRadix x+        (_, u) = floatRange x+        x = encodeFloat (b^n - 1) (u - n)++-- | The minimum (positive) normalized value for the type.+{-# SPECIALIZE minValue :: Double #-}+{-# SPECIALIZE minValue :: Float #-}+minValue :: (RealFloat a) => a+minValue = x+  where n = floatDigits x+        b = floatRadix x+        (l, _) = floatRange x+        x = encodeFloat (b^n - 1) (l - n - 1)
+ Setup.hs view
@@ -0,0 +1,3 @@+module Main where+import Distribution.Simple+main = defaultMain
+ numeric-limits.cabal view
@@ -0,0 +1,14 @@+Name:           numeric-limits+Cabal-Version:  >= 1.2+Version:        0.1.0.0+License:        BSD3+Author:         Lennart Augustsson+Maintainer:     Lennart Augustsson+Category:       Numerical+Synopsis:       Various floating point limit related constants.+Stability:      experimental+Build-type:     Simple+Description:    Various floating point limit related constants.+Library+  Build-Depends: base >= 3 && < 6+  Exposed-modules:      Numeric.Limits