Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alex D
GHC
Commits
cbfc632b
Commit
cbfc632b
authored
Oct 08, 2012
by
jwlato
Committed by
ian@well-typed.com
Oct 21, 2012
Browse files
move fromRational into rationalToFloat/Double
parent
e9ab31d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
libraries/base/GHC/Float.lhs
View file @
cbfc632b
...
...
@@ -230,19 +230,24 @@ instance Real Float where
instance Fractional Float where
(/) x y = divideFloat x y
fromRational (n:%0)
| n == 0 = 0/0
| n < 0 = (-1)/0
| otherwise = 1/0
fromRational (n:%d)
| n == 0 = encodeFloat 0 0
| n < 0 = -(fromRat'' minEx mantDigs (-n) d)
| otherwise = fromRat'' minEx mantDigs n d
where
minEx = FLT_MIN_EXP
mantDigs = FLT_MANT_DIG
{-# INLINE fromRational #-}
fromRational (n:%d) = rationalToFloat n d
recip x = 1.0 / x
rationalToFloat :: Integer -> Integer -> Float
{-# NOINLINE [1] rationalToFloat #-}
rationalToFloat n 0
| n == 0 = 0/0
| n < 0 = (-1)/0
| otherwise = 1/0
rationalToFloat n d
| n == 0 = encodeFloat 0 0
| n < 0 = -(fromRat'' minEx mantDigs (-n) d)
| otherwise = fromRat'' minEx mantDigs n d
where
minEx = FLT_MIN_EXP
mantDigs = FLT_MANT_DIG
-- RULES for Integer and Int
{-# RULES
"properFraction/Float->Integer" properFraction = properFractionFloatInteger
...
...
@@ -391,19 +396,24 @@ instance Real Double where
instance Fractional Double where
(/) x y = divideDouble x y
fromRational (n:%0)
| n == 0 = 0/0
| n < 0 = (-1)/0
| otherwise = 1/0
fromRational (n:%d)
| n == 0 = encodeFloat 0 0
| n < 0 = -(fromRat'' minEx mantDigs (-n) d)
| otherwise = fromRat'' minEx mantDigs n d
where
minEx = DBL_MIN_EXP
mantDigs = DBL_MANT_DIG
{-# INLINE fromRational #-}
fromRational (n:%d) = rationalToDouble n d
recip x = 1.0 / x
rationalToDouble :: Integer -> Integer -> Double
{-# NOINLINE [1] rationalToDouble #-}
rationalToDouble n 0
| n == 0 = 0/0
| n < 0 = (-1)/0
| otherwise = 1/0
rationalToDouble n d
| n == 0 = encodeFloat 0 0
| n < 0 = -(fromRat'' minEx mantDigs (-n) d)
| otherwise = fromRat'' minEx mantDigs n d
where
minEx = DBL_MIN_EXP
mantDigs = DBL_MANT_DIG
instance Floating Double where
pi = 3.141592653589793238
exp x = expDouble x
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment