1-- |
2-- Module    : Numeric.MathFunctions.Constants
3-- Copyright : (c) 2009, 2011 Bryan O'Sullivan
4-- License   : BSD3
5--
6-- Maintainer  : bos@serpentine.com
7-- Stability   : experimental
8-- Portability : portable
9--
10-- Constant values common to much numeric code.
11
12module Numeric.MathFunctions.Constants
13    (
14      -- * IEE754 constants
15      m_epsilon
16    , m_sqrt_eps
17    , m_huge
18    , m_tiny
19    , m_max_exp
20    , m_pos_inf
21    , m_neg_inf
22    , m_NaN
23    , m_max_log
24    , m_min_log
25      -- * Mathematical constants
26    , m_1_sqrt_2
27    , m_2_sqrt_pi
28    , m_ln_sqrt_2_pi
29    , m_sqrt_2
30    , m_sqrt_2_pi
31    , m_eulerMascheroni
32    ) where
33
34----------------------------------------------------------------
35-- IEE754 constants
36----------------------------------------------------------------
37
38-- | Largest representable finite value.
39m_huge :: Double
40m_huge = 1.7976931348623157e308
41{-# INLINE m_huge #-}
42
43-- | The smallest representable positive normalized value.
44m_tiny :: Double
45m_tiny = 2.2250738585072014e-308
46{-# INLINE m_tiny #-}
47
48-- | The largest 'Int' /x/ such that 2**(/x/-1) is approximately
49-- representable as a 'Double'.
50m_max_exp :: Int
51m_max_exp = 1024
52
53-- | Positive infinity.
54m_pos_inf :: Double
55m_pos_inf = 1/0
56{-# INLINE m_pos_inf #-}
57
58-- | Negative infinity.
59m_neg_inf :: Double
60m_neg_inf = -1/0
61{-# INLINE m_neg_inf #-}
62
63-- | Not a number.
64m_NaN :: Double
65m_NaN = 0/0
66{-# INLINE m_NaN #-}
67
68-- | Maximum possible finite value of @log x@
69m_max_log :: Double
70m_max_log = 709.782712893384
71{-# INLINE m_max_log #-}
72
73-- | Logarithm of smallest normalized double ('m_tiny')
74m_min_log :: Double
75m_min_log = -708.3964185322641
76{-# INLINE m_min_log #-}
77
78
79----------------------------------------------------------------
80-- Mathematical constants
81----------------------------------------------------------------
82
83-- | @sqrt 2@
84m_sqrt_2 :: Double
85m_sqrt_2 = 1.4142135623730950488016887242096980785696718753769480731766
86{-# INLINE m_sqrt_2 #-}
87
88-- | @sqrt (2 * pi)@
89m_sqrt_2_pi :: Double
90m_sqrt_2_pi = 2.5066282746310005024157652848110452530069867406099383166299
91{-# INLINE m_sqrt_2_pi #-}
92
93-- | @2 / sqrt pi@
94m_2_sqrt_pi :: Double
95m_2_sqrt_pi = 1.1283791670955125738961589031215451716881012586579977136881
96{-# INLINE m_2_sqrt_pi #-}
97
98-- | @1 / sqrt 2@
99m_1_sqrt_2 :: Double
100m_1_sqrt_2 = 0.7071067811865475244008443621048490392848359376884740365883
101{-# INLINE m_1_sqrt_2 #-}
102
103-- | The smallest 'Double' ε such that 1 + ε ≠ 1.
104m_epsilon :: Double
105m_epsilon = encodeFloat (signif+1) expo - 1.0
106    where (signif,expo) = decodeFloat (1.0::Double)
107
108-- | @sqrt m_epsilon@
109--
110-- @since 0.3.3.0
111m_sqrt_eps :: Double
112m_sqrt_eps = 1.4901161193847656e-8
113
114-- | @log(sqrt((2*pi))@
115m_ln_sqrt_2_pi :: Double
116m_ln_sqrt_2_pi = 0.9189385332046727417803297364056176398613974736377834128171
117{-# INLINE m_ln_sqrt_2_pi #-}
118
119-- | Euler–Mascheroni constant (γ = 0.57721...)
120m_eulerMascheroni :: Double
121m_eulerMascheroni = 0.5772156649015328606065121
122{-# INLINE m_eulerMascheroni #-}
123