{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP
, GHCForeignImportPrim
, NoImplicitPrelude
, MagicHash
, UnboxedTuples
, UnliftedFFITypes
#-}
{-# LANGUAGE CApiFFI #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_HADDOCK not-home #-}
#include "ieee-flpt.h"
#include "MachDeps.h"
module GHC.Float
( module GHC.Float
, Float(..), Double(..), Float#, Double#
, double2Int, int2Double, float2Int, int2Float
, eqFloat, eqDouble
) where
import Data.Maybe
import Data.Bits
import GHC.Base
import GHC.List
import GHC.Enum
import GHC.Show
import GHC.Num
import GHC.Real
import GHC.Word
import GHC.Arr
import GHC.Float.RealFracMethods
import GHC.Float.ConversionUtils
import GHC.Integer.Logarithms ( integerLogBase# )
import GHC.Integer.Logarithms.Internals
infixr 8 **
class (Fractional a) => Floating a where
pi :: a
exp, log, sqrt :: a -> a
(**), logBase :: a -> a -> a
sin, cos, tan :: a -> a
asin, acos, atan :: a -> a
sinh, cosh, tanh :: a -> a
asinh, acosh, atanh :: a -> a
log1p :: a -> a
expm1 :: a -> a
log1pexp :: a -> a
log1mexp :: a -> a
{-# INLINE (**) #-}
{-# INLINE logBase #-}
{-# INLINE sqrt #-}
{-# INLINE tan #-}
{-# INLINE tanh #-}
x :: a
x ** y :: a
y = a -> a
forall a. Floating a => a -> a
exp (a -> a
forall a. Floating a => a -> a
log a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
y)
logBase x :: a
x y :: a
y = a -> a
forall a. Floating a => a -> a
log a
y a -> a -> a
forall a. Fractional a => a -> a -> a
/ a -> a
forall a. Floating a => a -> a
log a
x
sqrt x :: a
x = a
x a -> a -> a
forall a. Floating a => a -> a -> a
** 0.5
tan x :: a
x = a -> a
forall a. Floating a => a -> a
sin a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ a -> a
forall a. Floating a => a -> a
cos a
x
tanh x :: a
x = a -> a
forall a. Floating a => a -> a
sinh a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ a -> a
forall a. Floating a => a -> a
cosh a
x
{-# INLINE log1p #-}
{-# INLINE expm1 #-}
{-# INLINE log1pexp #-}
{-# INLINE log1mexp #-}
log1p x :: a
x = a -> a
forall a. Floating a => a -> a
log (1 a -> a -> a
forall a. Num a => a -> a -> a
+ a
x)
expm1 x :: a
x = a -> a
forall a. Floating a => a -> a
exp a
x a -> a -> a
forall a. Num a => a -> a -> a
- 1
log1pexp x :: a
x = a -> a
forall a. Floating a => a -> a
log1p (a -> a
forall a. Floating a => a -> a
exp a
x)
log1mexp x :: a
x = a -> a
forall a. Floating a => a -> a
log1p (a -> a
forall a. Num a => a -> a
negate (a -> a
forall a. Floating a => a -> a
exp a
x))
class (RealFrac a, Floating a) => RealFloat a where
floatRadix :: a -> Integer
floatDigits :: a -> Int
floatRange :: a -> (Int,Int)
decodeFloat :: a -> (Integer,Int)
encodeFloat :: Integer -> Int -> a
exponent :: a -> Int
significand :: a -> a
scaleFloat :: Int -> a -> a
isNaN :: a -> Bool
isInfinite :: a -> Bool
isDenormalized :: a -> Bool
isNegativeZero :: a -> Bool
isIEEE :: a -> Bool
atan2 :: a -> a -> a
exponent x :: a
x = if Integer
m Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 then 0 else Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. RealFloat a => a -> Int
floatDigits a
x
where (m :: Integer
m,n :: Int
n) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
significand x :: a
x = Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m (Int -> Int
forall a. Num a => a -> a
negate (a -> Int
forall a. RealFloat a => a -> Int
floatDigits a
x))
where (m :: Integer
m,_) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
scaleFloat 0 x :: a
x = a
x
scaleFloat k :: Int
k x :: a
x
| Bool
isFix = a
x
| Bool
otherwise = Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
clamp Int
b Int
k)
where (m :: Integer
m,n :: Int
n) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
(l :: Int
l,h :: Int
h) = a -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange a
x
d :: Int
d = a -> Int
forall a. RealFloat a => a -> Int
floatDigits a
x
b :: Int
b = Int
h Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 4Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
d
isFix :: Bool
isFix = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== 0 Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite a
x
atan2 y :: a
y x :: a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = a -> a
forall a. Floating a => a -> a
atan (a
ya -> a -> a
forall a. Fractional a => a -> a -> a
/a
x)
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== 0 Bool -> Bool -> Bool
&& a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = a
forall a. Floating a => a
pia -> a -> a
forall a. Fractional a => a -> a -> a
/2
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 Bool -> Bool -> Bool
&& a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = a
forall a. Floating a => a
pi a -> a -> a
forall a. Num a => a -> a -> a
+ a -> a
forall a. Floating a => a -> a
atan (a
ya -> a -> a
forall a. Fractional a => a -> a -> a
/a
x)
|(a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 Bool -> Bool -> Bool
&& a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0) Bool -> Bool -> Bool
||
(a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
y) Bool -> Bool -> Bool
||
(a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
y)
= -a -> a -> a
forall a. RealFloat a => a -> a -> a
atan2 (-a
y) a
x
| a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== 0 Bool -> Bool -> Bool
&& (a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x)
= a
forall a. Floating a => a
pi
| a
xa -> a -> Bool
forall a. Eq a => a -> a -> Bool
==0 Bool -> Bool -> Bool
&& a
ya -> a -> Bool
forall a. Eq a => a -> a -> Bool
==0 = a
y
| Bool
otherwise = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
y
instance Num Float where
+ :: Float -> Float -> Float
(+) x :: Float
x y :: Float
y = Float -> Float -> Float
plusFloat Float
x Float
y
(-) x :: Float
x y :: Float
y = Float -> Float -> Float
minusFloat Float
x Float
y
negate :: Float -> Float
negate x :: Float
x = Float -> Float
negateFloat Float
x
* :: Float -> Float -> Float
(*) x :: Float
x y :: Float
y = Float -> Float -> Float
timesFloat Float
x Float
y
abs :: Float -> Float
abs x :: Float
x = Float -> Float
fabsFloat Float
x
signum :: Float -> Float
signum x :: Float
x | Float
x Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = 1
| Float
x Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = Float -> Float
negateFloat 1
| Bool
otherwise = Float
x
{-# INLINE fromInteger #-}
fromInteger :: Integer -> Float
fromInteger i :: Integer
i = Float# -> Float
F# (Integer -> Float#
floatFromInteger Integer
i)
instance Real Float where
toRational :: Float -> Rational
toRational (F# x# :: Float#
x#) =
case Float# -> (# Int#, Int# #)
decodeFloat_Int# Float#
x# of
(# m# :: Int#
m#, e# :: Int#
e# #)
| Int# -> Bool
isTrue# (Int#
e# Int# -> Int# -> Int#
>=# 0#) ->
(Int# -> Integer
smallInteger Int#
m# Integer -> Int# -> Integer
`shiftLInteger` Int#
e#) Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% 1
| Int# -> Bool
isTrue# ((Int# -> Word#
int2Word# Int#
m# Word# -> Word# -> Word#
`and#` 1##) Word# -> Word# -> Int#
`eqWord#` 0##) ->
case Int# -> Int# -> (# Integer, Int# #)
elimZerosInt# Int#
m# (Int# -> Int#
negateInt# Int#
e#) of
(# n :: Integer
n, d# :: Int#
d# #) -> Integer
n Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer -> Int# -> Integer
shiftLInteger 1 Int#
d#
| Bool
otherwise ->
Int# -> Integer
smallInteger Int#
m# Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer -> Int# -> Integer
shiftLInteger 1 (Int# -> Int#
negateInt# Int#
e#)
instance Fractional Float where
/ :: Float -> Float -> Float
(/) x :: Float
x y :: Float
y = Float -> Float -> Float
divideFloat Float
x Float
y
{-# INLINE fromRational #-}
fromRational :: Rational -> Float
fromRational (n :: Integer
n:%d :: Integer
d) = Integer -> Integer -> Float
rationalToFloat Integer
n Integer
d
recip :: Float -> Float
recip x :: Float
x = 1.0 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
x
rationalToFloat :: Integer -> Integer -> Float
{-# NOINLINE [1] rationalToFloat #-}
rationalToFloat :: Integer -> Integer -> Float
rationalToFloat n :: Integer
n 0
| Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 = 0Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/0
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = (-1)Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/0
| Bool
otherwise = 1Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/0
rationalToFloat n :: Integer
n d :: Integer
d
| Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 = Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
encodeFloat 0 0
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = -(Int -> Int -> Integer -> Integer -> Float
forall a. RealFloat a => Int -> Int -> Integer -> Integer -> a
fromRat'' Int
minEx Int
mantDigs (-Integer
n) Integer
d)
| Bool
otherwise = Int -> Int -> Integer -> Integer -> Float
forall a. RealFloat a => Int -> Int -> Integer -> Integer -> a
fromRat'' Int
minEx Int
mantDigs Integer
n Integer
d
where
minEx :: Int
minEx = FLT_MIN_EXP
mantDigs :: Int
mantDigs = FLT_MANT_DIG
{-# RULES
"properFraction/Float->Integer" properFraction = properFractionFloatInteger
"truncate/Float->Integer" truncate = truncateFloatInteger
"floor/Float->Integer" floor = floorFloatInteger
"ceiling/Float->Integer" ceiling = ceilingFloatInteger
"round/Float->Integer" round = roundFloatInteger
"properFraction/Float->Int" properFraction = properFractionFloatInt
"truncate/Float->Int" truncate = float2Int
"floor/Float->Int" floor = floorFloatInt
"ceiling/Float->Int" ceiling = ceilingFloatInt
"round/Float->Int" round = roundFloatInt
#-}
instance RealFrac Float where
{-# INLINE [1] ceiling #-}
{-# INLINE [1] floor #-}
{-# INLINE [1] truncate #-}
#if FLT_RADIX != 2
#error FLT_RADIX must be 2
#endif
properFraction :: Float -> (b, Float)
properFraction (F# x# :: Float#
x#)
= case Float# -> (# Int#, Int# #)
decodeFloat_Int# Float#
x# of
(# m# :: Int#
m#, n# :: Int#
n# #) ->
let m :: Int
m = Int# -> Int
I# Int#
m#
n :: Int
n = Int# -> Int
I# Int#
n#
in
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0
then (Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m b -> b -> b
forall a. Num a => a -> a -> a
* (2 b -> Int -> b
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
n), 0.0)
else let i :: Int
i = if Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then Int
m Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int -> Int
forall a. Num a => a -> a
negate Int
n
else Int -> Int
forall a. Num a => a -> a
negate (Int -> Int
forall a. Num a => a -> a
negate Int
m Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int -> Int
forall a. Num a => a -> a
negate Int
n)
f :: Int
f = Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
i Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftL` Int -> Int
forall a. Num a => a -> a
negate Int
n)
in (Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i, Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
encodeFloat (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
f) Int
n)
truncate :: Float -> b
truncate x :: Float
x = case Float -> (b, Float)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Float
x of
(n :: b
n,_) -> b
n
round :: Float -> b
round x :: Float
x = case Float -> (b, Float)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Float
x of
(n :: b
n,r :: Float
r) -> let
m :: b
m = if Float
r Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< 0.0 then b
n b -> b -> b
forall a. Num a => a -> a -> a
- 1 else b
n b -> b -> b
forall a. Num a => a -> a -> a
+ 1
half_down :: Float
half_down = Float -> Float
forall a. Num a => a -> a
abs Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
- 0.5
in
case (Float -> Float -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Float
half_down 0.0) of
LT -> b
n
EQ -> if b -> Bool
forall a. Integral a => a -> Bool
even b
n then b
n else b
m
GT -> b
m
ceiling :: Float -> b
ceiling x :: Float
x = case Float -> (b, Float)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Float
x of
(n :: b
n,r :: Float
r) -> if Float
r Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
> 0.0 then b
n b -> b -> b
forall a. Num a => a -> a -> a
+ 1 else b
n
floor :: Float -> b
floor x :: Float
x = case Float -> (b, Float)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Float
x of
(n :: b
n,r :: Float
r) -> if Float
r Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< 0.0 then b
n b -> b -> b
forall a. Num a => a -> a -> a
- 1 else b
n
instance Floating Float where
pi :: Float
pi = 3.141592653589793238
exp :: Float -> Float
exp x :: Float
x = Float -> Float
expFloat Float
x
log :: Float -> Float
log x :: Float
x = Float -> Float
logFloat Float
x
sqrt :: Float -> Float
sqrt x :: Float
x = Float -> Float
sqrtFloat Float
x
sin :: Float -> Float
sin x :: Float
x = Float -> Float
sinFloat Float
x
cos :: Float -> Float
cos x :: Float
x = Float -> Float
cosFloat Float
x
tan :: Float -> Float
tan x :: Float
x = Float -> Float
tanFloat Float
x
asin :: Float -> Float
asin x :: Float
x = Float -> Float
asinFloat Float
x
acos :: Float -> Float
acos x :: Float
x = Float -> Float
acosFloat Float
x
atan :: Float -> Float
atan x :: Float
x = Float -> Float
atanFloat Float
x
sinh :: Float -> Float
sinh x :: Float
x = Float -> Float
sinhFloat Float
x
cosh :: Float -> Float
cosh x :: Float
x = Float -> Float
coshFloat Float
x
tanh :: Float -> Float
tanh x :: Float
x = Float -> Float
tanhFloat Float
x
** :: Float -> Float -> Float
(**) x :: Float
x y :: Float
y = Float -> Float -> Float
powerFloat Float
x Float
y
logBase :: Float -> Float -> Float
logBase x :: Float
x y :: Float
y = Float -> Float
forall a. Floating a => a -> a
log Float
y Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float -> Float
forall a. Floating a => a -> a
log Float
x
asinh :: Float -> Float
asinh x :: Float
x = Float -> Float
asinhFloat Float
x
acosh :: Float -> Float
acosh x :: Float
x = Float -> Float
acoshFloat Float
x
atanh :: Float -> Float
atanh x :: Float
x = Float -> Float
atanhFloat Float
x
log1p :: Float -> Float
log1p = Float -> Float
log1pFloat
expm1 :: Float -> Float
expm1 = Float -> Float
expm1Float
log1mexp :: Float -> Float
log1mexp a :: Float
a
| Float
a Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= Float -> Float
forall a. Floating a => a -> a
log 2 = Float -> Float
forall a. Floating a => a -> a
log (Float -> Float
forall a. Num a => a -> a
negate (Float -> Float
expm1Float Float
a))
| Bool
otherwise = Float -> Float
log1pFloat (Float -> Float
forall a. Num a => a -> a
negate (Float -> Float
forall a. Floating a => a -> a
exp Float
a))
{-# INLINE log1mexp #-}
log1pexp :: Float -> Float
log1pexp a :: Float
a
| Float
a Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= 18 = Float -> Float
log1pFloat (Float -> Float
forall a. Floating a => a -> a
exp Float
a)
| Float
a Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= 100 = Float
a Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float -> Float
forall a. Floating a => a -> a
exp (Float -> Float
forall a. Num a => a -> a
negate Float
a)
| Bool
otherwise = Float
a
{-# INLINE log1pexp #-}
instance RealFloat Float where
floatRadix :: Float -> Integer
floatRadix _ = FLT_RADIX
floatDigits :: Float -> Int
floatDigits _ = FLT_MANT_DIG
floatRange :: Float -> (Int, Int)
floatRange _ = (FLT_MIN_EXP, FLT_MAX_EXP)
decodeFloat :: Float -> (Integer, Int)
decodeFloat (F# f# :: Float#
f#) = case Float# -> (# Int#, Int# #)
decodeFloat_Int# Float#
f# of
(# i :: Int#
i, e :: Int#
e #) -> (Int# -> Integer
smallInteger Int#
i, Int# -> Int
I# Int#
e)
encodeFloat :: Integer -> Int -> Float
encodeFloat i :: Integer
i (I# e :: Int#
e) = Float# -> Float
F# (Integer -> Int# -> Float#
encodeFloatInteger Integer
i Int#
e)
exponent :: Float -> Int
exponent x :: Float
x = case Float -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Float
x of
(m :: Integer
m,n :: Int
n) -> if Integer
m Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 then 0 else Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Float -> Int
forall a. RealFloat a => a -> Int
floatDigits Float
x
significand :: Float -> Float
significand x :: Float
x = case Float -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Float
x of
(m :: Integer
m,_) -> Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m (Int -> Int
forall a. Num a => a -> a
negate (Float -> Int
forall a. RealFloat a => a -> Int
floatDigits Float
x))
scaleFloat :: Int -> Float -> Float
scaleFloat 0 x :: Float
x = Float
x
scaleFloat k :: Int
k x :: Float
x
| Bool
isFix = Float
x
| Bool
otherwise = case Float -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Float
x of
(m :: Integer
m,n :: Int
n) -> Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
clamp Int
bf Int
k)
where bf :: Int
bf = FLT_MAX_EXP - (FLT_MIN_EXP) + 4*FLT_MANT_DIG
isFix :: Bool
isFix = Float
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== 0 Bool -> Bool -> Bool
|| Float -> Int
isFloatFinite Float
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
isNaN :: Float -> Bool
isNaN x :: Float
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Float -> Int
isFloatNaN Float
x
isInfinite :: Float -> Bool
isInfinite x :: Float
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Float -> Int
isFloatInfinite Float
x
isDenormalized :: Float -> Bool
isDenormalized x :: Float
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Float -> Int
isFloatDenormalized Float
x
isNegativeZero :: Float -> Bool
isNegativeZero x :: Float
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Float -> Int
isFloatNegativeZero Float
x
isIEEE :: Float -> Bool
isIEEE _ = Bool
True
instance Show Float where
showsPrec :: Int -> Float -> ShowS
showsPrec x :: Int
x = (Float -> ShowS) -> Int -> Float -> ShowS
forall a. RealFloat a => (a -> ShowS) -> Int -> a -> ShowS
showSignedFloat Float -> ShowS
forall a. RealFloat a => a -> ShowS
showFloat Int
x
showList :: [Float] -> ShowS
showList = (Float -> ShowS) -> [Float] -> ShowS
forall a. (a -> ShowS) -> [a] -> ShowS
showList__ (Int -> Float -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec 0)
instance Num Double where
+ :: Double -> Double -> Double
(+) x :: Double
x y :: Double
y = Double -> Double -> Double
plusDouble Double
x Double
y
(-) x :: Double
x y :: Double
y = Double -> Double -> Double
minusDouble Double
x Double
y
negate :: Double -> Double
negate x :: Double
x = Double -> Double
negateDouble Double
x
* :: Double -> Double -> Double
(*) x :: Double
x y :: Double
y = Double -> Double -> Double
timesDouble Double
x Double
y
abs :: Double -> Double
abs x :: Double
x = Double -> Double
fabsDouble Double
x
signum :: Double -> Double
signum x :: Double
x | Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = 1
| Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = Double -> Double
negateDouble 1
| Bool
otherwise = Double
x
{-# INLINE fromInteger #-}
fromInteger :: Integer -> Double
fromInteger i :: Integer
i = Double# -> Double
D# (Integer -> Double#
doubleFromInteger Integer
i)
instance Real Double where
toRational :: Double -> Rational
toRational (D# x# :: Double#
x#) =
case Double# -> (# Integer, Int# #)
decodeDoubleInteger Double#
x# of
(# m :: Integer
m, e# :: Int#
e# #)
| Int# -> Bool
isTrue# (Int#
e# Int# -> Int# -> Int#
>=# 0#) ->
Integer -> Int# -> Integer
shiftLInteger Integer
m Int#
e# Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% 1
| Int# -> Bool
isTrue# ((Integer -> Word#
integerToWord Integer
m Word# -> Word# -> Word#
`and#` 1##) Word# -> Word# -> Int#
`eqWord#` 0##) ->
case Integer -> Int# -> (# Integer, Int# #)
elimZerosInteger Integer
m (Int# -> Int#
negateInt# Int#
e#) of
(# n :: Integer
n, d# :: Int#
d# #) -> Integer
n Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer -> Int# -> Integer
shiftLInteger 1 Int#
d#
| Bool
otherwise ->
Integer
m Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer -> Int# -> Integer
shiftLInteger 1 (Int# -> Int#
negateInt# Int#
e#)
instance Fractional Double where
/ :: Double -> Double -> Double
(/) x :: Double
x y :: Double
y = Double -> Double -> Double
divideDouble Double
x Double
y
{-# INLINE fromRational #-}
fromRational :: Rational -> Double
fromRational (n :: Integer
n:%d :: Integer
d) = Integer -> Integer -> Double
rationalToDouble Integer
n Integer
d
recip :: Double -> Double
recip x :: Double
x = 1.0 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
x
rationalToDouble :: Integer -> Integer -> Double
{-# NOINLINE [1] rationalToDouble #-}
rationalToDouble :: Integer -> Integer -> Double
rationalToDouble n :: Integer
n 0
| Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 = 0Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/0
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = (-1)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/0
| Bool
otherwise = 1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/0
rationalToDouble n :: Integer
n d :: Integer
d
| Integer
n Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 = Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
encodeFloat 0 0
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = -(Int -> Int -> Integer -> Integer -> Double
forall a. RealFloat a => Int -> Int -> Integer -> Integer -> a
fromRat'' Int
minEx Int
mantDigs (-Integer
n) Integer
d)
| Bool
otherwise = Int -> Int -> Integer -> Integer -> Double
forall a. RealFloat a => Int -> Int -> Integer -> Integer -> a
fromRat'' Int
minEx Int
mantDigs Integer
n Integer
d
where
minEx :: Int
minEx = DBL_MIN_EXP
mantDigs :: Int
mantDigs = DBL_MANT_DIG
instance Floating Double where
pi :: Double
pi = 3.141592653589793238
exp :: Double -> Double
exp x :: Double
x = Double -> Double
expDouble Double
x
log :: Double -> Double
log x :: Double
x = Double -> Double
logDouble Double
x
sqrt :: Double -> Double
sqrt x :: Double
x = Double -> Double
sqrtDouble Double
x
sin :: Double -> Double
sin x :: Double
x = Double -> Double
sinDouble Double
x
cos :: Double -> Double
cos x :: Double
x = Double -> Double
cosDouble Double
x
tan :: Double -> Double
tan x :: Double
x = Double -> Double
tanDouble Double
x
asin :: Double -> Double
asin x :: Double
x = Double -> Double
asinDouble Double
x
acos :: Double -> Double
acos x :: Double
x = Double -> Double
acosDouble Double
x
atan :: Double -> Double
atan x :: Double
x = Double -> Double
atanDouble Double
x
sinh :: Double -> Double
sinh x :: Double
x = Double -> Double
sinhDouble Double
x
cosh :: Double -> Double
cosh x :: Double
x = Double -> Double
coshDouble Double
x
tanh :: Double -> Double
tanh x :: Double
x = Double -> Double
tanhDouble Double
x
** :: Double -> Double -> Double
(**) x :: Double
x y :: Double
y = Double -> Double -> Double
powerDouble Double
x Double
y
logBase :: Double -> Double -> Double
logBase x :: Double
x y :: Double
y = Double -> Double
forall a. Floating a => a -> a
log Double
y Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
log Double
x
asinh :: Double -> Double
asinh x :: Double
x = Double -> Double
asinhDouble Double
x
acosh :: Double -> Double
acosh x :: Double
x = Double -> Double
acoshDouble Double
x
atanh :: Double -> Double
atanh x :: Double
x = Double -> Double
atanhDouble Double
x
log1p :: Double -> Double
log1p = Double -> Double
log1pDouble
expm1 :: Double -> Double
expm1 = Double -> Double
expm1Double
log1mexp :: Double -> Double
log1mexp a :: Double
a
| Double
a Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double -> Double
forall a. Floating a => a -> a
log 2 = Double -> Double
forall a. Floating a => a -> a
log (Double -> Double
forall a. Num a => a -> a
negate (Double -> Double
expm1Double Double
a))
| Bool
otherwise = Double -> Double
log1pDouble (Double -> Double
forall a. Num a => a -> a
negate (Double -> Double
forall a. Floating a => a -> a
exp Double
a))
{-# INLINE log1mexp #-}
log1pexp :: Double -> Double
log1pexp a :: Double
a
| Double
a Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= 18 = Double -> Double
log1pDouble (Double -> Double
forall a. Floating a => a -> a
exp Double
a)
| Double
a Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= 100 = Double
a Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double
forall a. Floating a => a -> a
exp (Double -> Double
forall a. Num a => a -> a
negate Double
a)
| Bool
otherwise = Double
a
{-# INLINE log1pexp #-}
{-# RULES
"properFraction/Double->Integer" properFraction = properFractionDoubleInteger
"truncate/Double->Integer" truncate = truncateDoubleInteger
"floor/Double->Integer" floor = floorDoubleInteger
"ceiling/Double->Integer" ceiling = ceilingDoubleInteger
"round/Double->Integer" round = roundDoubleInteger
"properFraction/Double->Int" properFraction = properFractionDoubleInt
"truncate/Double->Int" truncate = double2Int
"floor/Double->Int" floor = floorDoubleInt
"ceiling/Double->Int" ceiling = ceilingDoubleInt
"round/Double->Int" round = roundDoubleInt
#-}
instance RealFrac Double where
{-# INLINE [1] ceiling #-}
{-# INLINE [1] floor #-}
{-# INLINE [1] truncate #-}
properFraction :: Double -> (b, Double)
properFraction x :: Double
x
= case (Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Double
x) of { (m :: Integer
m,n :: Int
n) ->
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then
(Integer -> b
forall a. Num a => Integer -> a
fromInteger Integer
m b -> b -> b
forall a. Num a => a -> a -> a
* 2 b -> Int -> b
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
n, 0.0)
else
case (Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
quotRem Integer
m (2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^(Int -> Int
forall a. Num a => a -> a
negate Int
n))) of { (w :: Integer
w,r :: Integer
r) ->
(Integer -> b
forall a. Num a => Integer -> a
fromInteger Integer
w, Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
r Int
n)
}
}
truncate :: Double -> b
truncate x :: Double
x = case Double -> (b, Double)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Double
x of
(n :: b
n,_) -> b
n
round :: Double -> b
round x :: Double
x = case Double -> (b, Double)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Double
x of
(n :: b
n,r :: Double
r) -> let
m :: b
m = if Double
r Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< 0.0 then b
n b -> b -> b
forall a. Num a => a -> a -> a
- 1 else b
n b -> b -> b
forall a. Num a => a -> a -> a
+ 1
half_down :: Double
half_down = Double -> Double
forall a. Num a => a -> a
abs Double
r Double -> Double -> Double
forall a. Num a => a -> a -> a
- 0.5
in
case (Double -> Double -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Double
half_down 0.0) of
LT -> b
n
EQ -> if b -> Bool
forall a. Integral a => a -> Bool
even b
n then b
n else b
m
GT -> b
m
ceiling :: Double -> b
ceiling x :: Double
x = case Double -> (b, Double)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Double
x of
(n :: b
n,r :: Double
r) -> if Double
r Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> 0.0 then b
n b -> b -> b
forall a. Num a => a -> a -> a
+ 1 else b
n
floor :: Double -> b
floor x :: Double
x = case Double -> (b, Double)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Double
x of
(n :: b
n,r :: Double
r) -> if Double
r Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< 0.0 then b
n b -> b -> b
forall a. Num a => a -> a -> a
- 1 else b
n
instance RealFloat Double where
floatRadix :: Double -> Integer
floatRadix _ = FLT_RADIX
floatDigits :: Double -> Int
floatDigits _ = DBL_MANT_DIG
floatRange :: Double -> (Int, Int)
floatRange _ = (DBL_MIN_EXP, DBL_MAX_EXP)
decodeFloat :: Double -> (Integer, Int)
decodeFloat (D# x# :: Double#
x#)
= case Double# -> (# Integer, Int# #)
decodeDoubleInteger Double#
x# of
(# i :: Integer
i, j :: Int#
j #) -> (Integer
i, Int# -> Int
I# Int#
j)
encodeFloat :: Integer -> Int -> Double
encodeFloat i :: Integer
i (I# j :: Int#
j) = Double# -> Double
D# (Integer -> Int# -> Double#
encodeDoubleInteger Integer
i Int#
j)
exponent :: Double -> Int
exponent x :: Double
x = case Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Double
x of
(m :: Integer
m,n :: Int
n) -> if Integer
m Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 0 then 0 else Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Double -> Int
forall a. RealFloat a => a -> Int
floatDigits Double
x
significand :: Double -> Double
significand x :: Double
x = case Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Double
x of
(m :: Integer
m,_) -> Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m (Int -> Int
forall a. Num a => a -> a
negate (Double -> Int
forall a. RealFloat a => a -> Int
floatDigits Double
x))
scaleFloat :: Int -> Double -> Double
scaleFloat 0 x :: Double
x = Double
x
scaleFloat k :: Int
k x :: Double
x
| Bool
isFix = Double
x
| Bool
otherwise = case Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat Double
x of
(m :: Integer
m,n :: Int
n) -> Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
clamp Int
bd Int
k)
where bd :: Int
bd = DBL_MAX_EXP - (DBL_MIN_EXP) + 4*DBL_MANT_DIG
isFix :: Bool
isFix = Double
x Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== 0 Bool -> Bool -> Bool
|| Double -> Int
isDoubleFinite Double
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
isNaN :: Double -> Bool
isNaN x :: Double
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Double -> Int
isDoubleNaN Double
x
isInfinite :: Double -> Bool
isInfinite x :: Double
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Double -> Int
isDoubleInfinite Double
x
isDenormalized :: Double -> Bool
isDenormalized x :: Double
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Double -> Int
isDoubleDenormalized Double
x
isNegativeZero :: Double -> Bool
isNegativeZero x :: Double
x = 0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Double -> Int
isDoubleNegativeZero Double
x
isIEEE :: Double -> Bool
isIEEE _ = Bool
True
instance Show Double where
showsPrec :: Int -> Double -> ShowS
showsPrec x :: Int
x = (Double -> ShowS) -> Int -> Double -> ShowS
forall a. RealFloat a => (a -> ShowS) -> Int -> a -> ShowS
showSignedFloat Double -> ShowS
forall a. RealFloat a => a -> ShowS
showFloat Int
x
showList :: [Double] -> ShowS
showList = (Double -> ShowS) -> [Double] -> ShowS
forall a. (a -> ShowS) -> [a] -> ShowS
showList__ (Int -> Double -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec 0)
instance Enum Float where
succ :: Float -> Float
succ x :: Float
x = Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
+ 1
pred :: Float -> Float
pred x :: Float
x = Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
- 1
toEnum :: Int -> Float
toEnum = Int -> Float
int2Float
fromEnum :: Float -> Int
fromEnum = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer -> Int) -> (Float -> Integer) -> Float -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate
enumFrom :: Float -> [Float]
enumFrom = Float -> [Float]
forall a. Fractional a => a -> [a]
numericEnumFrom
enumFromTo :: Float -> Float -> [Float]
enumFromTo = Float -> Float -> [Float]
forall a. (Ord a, Fractional a) => a -> a -> [a]
numericEnumFromTo
enumFromThen :: Float -> Float -> [Float]
enumFromThen = Float -> Float -> [Float]
forall a. Fractional a => a -> a -> [a]
numericEnumFromThen
enumFromThenTo :: Float -> Float -> Float -> [Float]
enumFromThenTo = Float -> Float -> Float -> [Float]
forall a. (Ord a, Fractional a) => a -> a -> a -> [a]
numericEnumFromThenTo
instance Enum Double where
succ :: Double -> Double
succ x :: Double
x = Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
+ 1
pred :: Double -> Double
pred x :: Double
x = Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- 1
toEnum :: Int -> Double
toEnum = Int -> Double
int2Double
fromEnum :: Double -> Int
fromEnum = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer -> Int) -> (Double -> Integer) -> Double -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate
enumFrom :: Double -> [Double]
enumFrom = Double -> [Double]
forall a. Fractional a => a -> [a]
numericEnumFrom
enumFromTo :: Double -> Double -> [Double]
enumFromTo = Double -> Double -> [Double]
forall a. (Ord a, Fractional a) => a -> a -> [a]
numericEnumFromTo
enumFromThen :: Double -> Double -> [Double]
enumFromThen = Double -> Double -> [Double]
forall a. Fractional a => a -> a -> [a]
numericEnumFromThen
enumFromThenTo :: Double -> Double -> Double -> [Double]
enumFromThenTo = Double -> Double -> Double -> [Double]
forall a. (Ord a, Fractional a) => a -> a -> a -> [a]
numericEnumFromThenTo
showFloat :: (RealFloat a) => a -> ShowS
showFloat :: a -> ShowS
showFloat x :: a
x = String -> ShowS
showString (FFFormat -> Maybe Int -> a -> String
forall a. RealFloat a => FFFormat -> Maybe Int -> a -> String
formatRealFloat FFFormat
FFGeneric Maybe Int
forall a. Maybe a
Nothing a
x)
data FFFormat = FFExponent | FFFixed | FFGeneric
formatRealFloat :: (RealFloat a) => FFFormat -> Maybe Int -> a -> String
formatRealFloat :: FFFormat -> Maybe Int -> a -> String
formatRealFloat fmt :: FFFormat
fmt decs :: Maybe Int
decs x :: a
x = FFFormat -> Maybe Int -> Bool -> a -> String
forall a.
RealFloat a =>
FFFormat -> Maybe Int -> Bool -> a -> String
formatRealFloatAlt FFFormat
fmt Maybe Int
decs Bool
False a
x
formatRealFloatAlt :: (RealFloat a) => FFFormat -> Maybe Int -> Bool -> a
-> String
formatRealFloatAlt :: FFFormat -> Maybe Int -> Bool -> a -> String
formatRealFloatAlt fmt :: FFFormat
fmt decs :: Maybe Int
decs alt :: Bool
alt x :: a
x
| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x = "NaN"
| a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite a
x = if a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 then "-Infinity" else "Infinity"
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x = '-'Char -> ShowS
forall a. a -> [a] -> [a]
:FFFormat -> ([Int], Int) -> String
doFmt FFFormat
fmt (Integer -> a -> ([Int], Int)
forall a. RealFloat a => Integer -> a -> ([Int], Int)
floatToDigits (Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
base) (-a
x))
| Bool
otherwise = FFFormat -> ([Int], Int) -> String
doFmt FFFormat
fmt (Integer -> a -> ([Int], Int)
forall a. RealFloat a => Integer -> a -> ([Int], Int)
floatToDigits (Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
base) a
x)
where
base :: Int
base = 10
doFmt :: FFFormat -> ([Int], Int) -> String
doFmt format :: FFFormat
format (is :: [Int]
is, e :: Int
e) =
let ds :: String
ds = (Int -> Char) -> [Int] -> String
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
is in
case FFFormat
format of
FFGeneric ->
FFFormat -> ([Int], Int) -> String
doFmt (if Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0 Bool -> Bool -> Bool
|| Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 7 then FFFormat
FFExponent else FFFormat
FFFixed)
([Int]
is,Int
e)
FFExponent ->
case Maybe Int
decs of
Nothing ->
let show_e' :: String
show_e' = Int -> String
forall a. Show a => a -> String
show (Int
eInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) in
case String
ds of
"0" -> "0.0e0"
[d :: Char
d] -> Char
d Char -> ShowS
forall a. a -> [a] -> [a]
: ".0e" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
show_e'
(d :: Char
d:ds' :: String
ds') -> Char
d Char -> ShowS
forall a. a -> [a] -> [a]
: '.' Char -> ShowS
forall a. a -> [a] -> [a]
: String
ds' String -> ShowS
forall a. [a] -> [a] -> [a]
++ "e" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
show_e'
[] -> ShowS
forall a. String -> a
errorWithoutStackTrace "formatRealFloat/doFmt/FFExponent: []"
Just d :: Int
d | Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 ->
case [Int]
is of
[0] -> "0e0"
_ ->
let
(ei :: Int
ei,is' :: [Int]
is') = Int -> Int -> [Int] -> (Int, [Int])
roundTo Int
base 1 [Int]
is
n :: Char
n:_ = (Int -> Char) -> [Int] -> String
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit (if Int
ei Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 then [Int] -> [Int]
forall a. [a] -> [a]
init [Int]
is' else [Int]
is')
in Char
n Char -> ShowS
forall a. a -> [a] -> [a]
: 'e' Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> String
forall a. Show a => a -> String
show (Int
eInt -> Int -> Int
forall a. Num a => a -> a -> a
-1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ei)
Just dec :: Int
dec ->
let dec' :: Int
dec' = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
dec 1 in
case [Int]
is of
[0] -> '0' Char -> ShowS
forall a. a -> [a] -> [a]
:'.' Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> ShowS
forall a. Int -> [a] -> [a]
take Int
dec' (Char -> String
forall a. a -> [a]
repeat '0') String -> ShowS
forall a. [a] -> [a] -> [a]
++ "e0"
_ ->
let
(ei :: Int
ei,is' :: [Int]
is') = Int -> Int -> [Int] -> (Int, [Int])
roundTo Int
base (Int
dec'Int -> Int -> Int
forall a. Num a => a -> a -> a
+1) [Int]
is
(d :: Char
d:ds' :: String
ds') = (Int -> Char) -> [Int] -> String
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit (if Int
ei Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 then [Int] -> [Int]
forall a. [a] -> [a]
init [Int]
is' else [Int]
is')
in
Char
dChar -> ShowS
forall a. a -> [a] -> [a]
:'.'Char -> ShowS
forall a. a -> [a] -> [a]
:String
ds' String -> ShowS
forall a. [a] -> [a] -> [a]
++ 'e'Char -> ShowS
forall a. a -> [a] -> [a]
:Int -> String
forall a. Show a => a -> String
show (Int
eInt -> Int -> Int
forall a. Num a => a -> a -> a
-1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ei)
FFFixed ->
let
mk0 :: ShowS
mk0 ls :: String
ls = case String
ls of { "" -> "0" ; _ -> String
ls}
in
case Maybe Int
decs of
Nothing
| Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 -> "0." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> Char -> String
forall a. Int -> a -> [a]
replicate (-Int
e) '0' String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
ds
| Bool
otherwise ->
let
f :: a -> String -> ShowS
f 0 s :: String
s rs :: String
rs = ShowS
mk0 (ShowS
forall a. [a] -> [a]
reverse String
s) String -> ShowS
forall a. [a] -> [a] -> [a]
++ '.'Char -> ShowS
forall a. a -> [a] -> [a]
:ShowS
mk0 String
rs
f n :: a
n s :: String
s "" = a -> String -> ShowS
f (a
na -> a -> a
forall a. Num a => a -> a -> a
-1) ('0'Char -> ShowS
forall a. a -> [a] -> [a]
:String
s) ""
f n :: a
n s :: String
s (r :: Char
r:rs :: String
rs) = a -> String -> ShowS
f (a
na -> a -> a
forall a. Num a => a -> a -> a
-1) (Char
rChar -> ShowS
forall a. a -> [a] -> [a]
:String
s) String
rs
in
Int -> String -> ShowS
forall a. (Eq a, Num a) => a -> String -> ShowS
f Int
e "" String
ds
Just dec :: Int
dec ->
let dec' :: Int
dec' = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
dec 0 in
if Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then
let
(ei :: Int
ei,is' :: [Int]
is') = Int -> Int -> [Int] -> (Int, [Int])
roundTo Int
base (Int
dec' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
e) [Int]
is
(ls :: String
ls,rs :: String
rs) = Int -> String -> (String, String)
forall a. Int -> [a] -> ([a], [a])
splitAt (Int
eInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ei) ((Int -> Char) -> [Int] -> String
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
is')
in
ShowS
mk0 String
ls String -> ShowS
forall a. [a] -> [a] -> [a]
++ (if String -> Bool
forall a. [a] -> Bool
null String
rs Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
alt then "" else '.'Char -> ShowS
forall a. a -> [a] -> [a]
:String
rs)
else
let
(ei :: Int
ei,is' :: [Int]
is') = Int -> Int -> [Int] -> (Int, [Int])
roundTo Int
base Int
dec' (Int -> Int -> [Int]
forall a. Int -> a -> [a]
replicate (-Int
e) 0 [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [Int]
is)
d :: Char
d:ds' :: String
ds' = (Int -> Char) -> [Int] -> String
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit (if Int
ei Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 then [Int]
is' else 0Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
is')
in
Char
d Char -> ShowS
forall a. a -> [a] -> [a]
: (if String -> Bool
forall a. [a] -> Bool
null String
ds' Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
alt then "" else '.'Char -> ShowS
forall a. a -> [a] -> [a]
:String
ds')
roundTo :: Int -> Int -> [Int] -> (Int,[Int])
roundTo :: Int -> Int -> [Int] -> (Int, [Int])
roundTo base :: Int
base d :: Int
d is :: [Int]
is =
case Int -> Bool -> [Int] -> (Int, [Int])
f Int
d Bool
True [Int]
is of
x :: (Int, [Int])
x@(0,_) -> (Int, [Int])
x
(1,xs :: [Int]
xs) -> (1, 1Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
xs)
_ -> String -> (Int, [Int])
forall a. String -> a
errorWithoutStackTrace "roundTo: bad Value"
where
b2 :: Int
b2 = Int
base Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` 2
f :: Int -> Bool -> [Int] -> (Int, [Int])
f n :: Int
n _ [] = (0, Int -> Int -> [Int]
forall a. Int -> a -> [a]
replicate Int
n 0)
f 0 e :: Bool
e (x :: Int
x:xs :: [Int]
xs) | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b2 Bool -> Bool -> Bool
&& Bool
e Bool -> Bool -> Bool
&& (Int -> Bool) -> [Int] -> Bool
forall a. (a -> Bool) -> [a] -> Bool
all (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) [Int]
xs = (0, [])
| Bool
otherwise = (if Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
b2 then 1 else 0, [])
f n :: Int
n _ (i :: Int
i:xs :: [Int]
xs)
| Int
i' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
base = (1,0Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
ds)
| Bool
otherwise = (0,Int
i'Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
ds)
where
(c :: Int
c,ds :: [Int]
ds) = Int -> Bool -> [Int] -> (Int, [Int])
f (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) (Int -> Bool
forall a. Integral a => a -> Bool
even Int
i) [Int]
xs
i' :: Int
i' = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i
floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)
floatToDigits :: Integer -> a -> ([Int], Int)
floatToDigits _ 0 = ([0], 0)
floatToDigits base :: Integer
base x :: a
x =
let
(f0 :: Integer
f0, e0 :: Int
e0) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
(minExp0 :: Int
minExp0, _) = a -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange a
x
p :: Int
p = a -> Int
forall a. RealFloat a => a -> Int
floatDigits a
x
b :: Integer
b = a -> Integer
forall a. RealFloat a => a -> Integer
floatRadix a
x
minExp :: Int
minExp = Int
minExp0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
p
(f :: Integer
f, e :: Int
e) =
let n :: Int
n = Int
minExp Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
e0 in
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 then (Integer
f0 Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`quot` (Integer -> Int -> Integer
expt Integer
b Int
n), Int
e0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
n) else (Integer
f0, Int
e0)
(r :: Integer
r, s :: Integer
s, mUp :: Integer
mUp, mDn :: Integer
mDn) =
if Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then
let be :: Integer
be = Integer -> Int -> Integer
expt Integer
b Int
e in
if Integer
f Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer -> Int -> Integer
expt Integer
b (Int
pInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) then
(Integer
fInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
beInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
bInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*2, 2Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
b, Integer
beInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
b, Integer
be)
else
(Integer
fInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
beInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*2, 2, Integer
be, Integer
be)
else
if Int
e Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
minExp Bool -> Bool -> Bool
&& Integer
f Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer -> Int -> Integer
expt Integer
b (Int
pInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) then
(Integer
fInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
bInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*2, Integer -> Int -> Integer
expt Integer
b (-Int
eInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
*2, Integer
b, 1)
else
(Integer
fInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*2, Integer -> Int -> Integer
expt Integer
b (-Int
e)Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
*2, 1, 1)
k :: Int
k :: Int
k =
let
k0 :: Int
k0 :: Int
k0 =
if Integer
b Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 2 Bool -> Bool -> Bool
&& Integer
base Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 10 then
let lx :: Int
lx = Int
p Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
e0
k1 :: Int
k1 = (Int
lx Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8651) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` 28738
in if Int
lx Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then Int
k1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1 else Int
k1
else
Float -> Int
forall a b. (RealFrac a, Integral b) => a -> b
ceiling ((Float -> Float
forall a. Floating a => a -> a
log (Integer -> Float
forall a. Num a => Integer -> a
fromInteger (Integer
fInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+1) :: Float) Float -> Float -> Float
forall a. Num a => a -> a -> a
+
Int -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
e Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
forall a. Floating a => a -> a
log (Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
b)) Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/
Float -> Float
forall a. Floating a => a -> a
log (Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
base))
fixup :: Int -> Int
fixup n :: Int
n =
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then
if Integer
r Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
mUp Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer -> Int -> Integer
expt Integer
base Int
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
s then Int
n else Int -> Int
fixup (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
else
if Integer -> Int -> Integer
expt Integer
base (-Int
n) Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* (Integer
r Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
mUp) Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
s then Int
n else Int -> Int
fixup (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
in
Int -> Int
fixup Int
k0
gen :: [Integer] -> Integer -> Integer -> Integer -> Integer -> [Integer]
gen ds :: [Integer]
ds rn :: Integer
rn sN :: Integer
sN mUpN :: Integer
mUpN mDnN :: Integer
mDnN =
let
(dn :: Integer
dn, rn' :: Integer
rn') = (Integer
rn Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
base) Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
sN
mUpN' :: Integer
mUpN' = Integer
mUpN Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
base
mDnN' :: Integer
mDnN' = Integer
mDnN Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
base
in
case (Integer
rn' Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
mDnN', Integer
rn' Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
mUpN' Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
sN) of
(True, False) -> Integer
dn Integer -> [Integer] -> [Integer]
forall a. a -> [a] -> [a]
: [Integer]
ds
(False, True) -> Integer
dnInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+1 Integer -> [Integer] -> [Integer]
forall a. a -> [a] -> [a]
: [Integer]
ds
(True, True) -> if Integer
rn' Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* 2 Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
sN then Integer
dn Integer -> [Integer] -> [Integer]
forall a. a -> [a] -> [a]
: [Integer]
ds else Integer
dnInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+1 Integer -> [Integer] -> [Integer]
forall a. a -> [a] -> [a]
: [Integer]
ds
(False, False) -> [Integer] -> Integer -> Integer -> Integer -> Integer -> [Integer]
gen (Integer
dnInteger -> [Integer] -> [Integer]
forall a. a -> [a] -> [a]
:[Integer]
ds) Integer
rn' Integer
sN Integer
mUpN' Integer
mDnN'
rds :: [Integer]
rds =
if Int
k Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 then
[Integer] -> Integer -> Integer -> Integer -> Integer -> [Integer]
gen [] Integer
r (Integer
s Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer -> Int -> Integer
expt Integer
base Int
k) Integer
mUp Integer
mDn
else
let bk :: Integer
bk = Integer -> Int -> Integer
expt Integer
base (-Int
k) in
[Integer] -> Integer -> Integer -> Integer -> Integer -> [Integer]
gen [] (Integer
r Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
bk) Integer
s (Integer
mUp Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
bk) (Integer
mDn Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
bk)
in
((Integer -> Int) -> [Integer] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Integer] -> [Integer]
forall a. [a] -> [a]
reverse [Integer]
rds), Int
k)
{-# RULES
"fromRat/Float" fromRat = (fromRational :: Rational -> Float)
"fromRat/Double" fromRat = (fromRational :: Rational -> Double)
#-}
{-# NOINLINE [1] fromRat #-}
fromRat :: (RealFloat a) => Rational -> a
fromRat :: Rational -> a
fromRat (n :: Integer
n :% 0) | Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = 1a -> a -> a
forall a. Fractional a => a -> a -> a
/0
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = -1a -> a -> a
forall a. Fractional a => a -> a -> a
/0
| Bool
otherwise = 0a -> a -> a
forall a. Fractional a => a -> a -> a
/0
fromRat (n :: Integer
n :% d :: Integer
d) | Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = Rational -> a
forall a. RealFloat a => Rational -> a
fromRat' (Integer
n Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer
d)
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = - Rational -> a
forall a. RealFloat a => Rational -> a
fromRat' ((-Integer
n) Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer
d)
| Bool
otherwise = Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat 0 0
fromRat' :: (RealFloat a) => Rational -> a
fromRat' :: Rational -> a
fromRat' x :: Rational
x = a
r
where b :: Integer
b = a -> Integer
forall a. RealFloat a => a -> Integer
floatRadix a
r
p :: Int
p = a -> Int
forall a. RealFloat a => a -> Int
floatDigits a
r
(minExp0 :: Int
minExp0, _) = a -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange a
r
minExp :: Int
minExp = Int
minExp0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
p
xMax :: Rational
xMax = Integer -> Rational
forall a. Real a => a -> Rational
toRational (Integer -> Int -> Integer
expt Integer
b Int
p)
p0 :: Int
p0 = (Integer -> Integer -> Int
integerLogBase Integer
b (Rational -> Integer
forall a. Ratio a -> a
numerator Rational
x) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Integer -> Integer -> Int
integerLogBase Integer
b (Rational -> Integer
forall a. Ratio a -> a
denominator Rational
x) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
p) Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` Int
minExp
f :: Rational
f = if Int
p0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0 then 1 Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% Integer -> Int -> Integer
expt Integer
b (-Int
p0) else Integer -> Int -> Integer
expt Integer
b Int
p0 Integer -> Integer -> Rational
forall a. a -> a -> Ratio a
:% 1
x0 :: Rational
x0 = Rational
x Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Rational
f
(x' :: Rational
x', p' :: Int
p') = if Rational
x0 Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
>= Rational
xMax then (Rational
x0 Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Integer -> Rational
forall a. Real a => a -> Rational
toRational Integer
b, Int
p0Int -> Int -> Int
forall a. Num a => a -> a -> a
+1) else (Rational
x0, Int
p0)
r :: a
r = Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat (Rational -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
round Rational
x') Int
p'
minExpt, maxExpt :: Int
minExpt :: Int
minExpt = 0
maxExpt :: Int
maxExpt = 1100
expt :: Integer -> Int -> Integer
expt :: Integer -> Int -> Integer
expt base :: Integer
base n :: Int
n =
if Integer
base Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 2 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
minExpt Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
maxExpt then
Array Int Integer
exptsArray Int Integer -> Int -> Integer
forall i e. Ix i => Array i e -> i -> e
!Int
n
else
if Integer
base Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 10 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
maxExpt10 then
Array Int Integer
expts10Array Int Integer -> Int -> Integer
forall i e. Ix i => Array i e -> i -> e
!Int
n
else
Integer
baseInteger -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
n
expts :: Array Int Integer
expts :: Array Int Integer
expts = (Int, Int) -> [(Int, Integer)] -> Array Int Integer
forall i e. Ix i => (i, i) -> [(i, e)] -> Array i e
array (Int
minExpt,Int
maxExpt) [(Int
n,2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
n) | Int
n <- [Int
minExpt .. Int
maxExpt]]
maxExpt10 :: Int
maxExpt10 :: Int
maxExpt10 = 324
expts10 :: Array Int Integer
expts10 :: Array Int Integer
expts10 = (Int, Int) -> [(Int, Integer)] -> Array Int Integer
forall i e. Ix i => (i, i) -> [(i, e)] -> Array i e
array (Int
minExpt,Int
maxExpt10) [(Int
n,10Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
n) | Int
n <- [Int
minExpt .. Int
maxExpt10]]
integerLogBase :: Integer -> Integer -> Int
integerLogBase :: Integer -> Integer -> Int
integerLogBase b :: Integer
b i :: Integer
i
| Integer
i Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
b = 0
| Integer
b Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== 2 = Int# -> Int
I# (Integer -> Int#
integerLog2# Integer
i)
| Bool
otherwise = Int# -> Int
I# (Integer -> Integer -> Int#
integerLogBase# Integer
b Integer
i)
{-# SPECIALISE fromRat'' :: Int -> Int -> Integer -> Integer -> Float,
Int -> Int -> Integer -> Integer -> Double #-}
fromRat'' :: RealFloat a => Int -> Int -> Integer -> Integer -> a
fromRat'' :: Int -> Int -> Integer -> Integer -> a
fromRat'' minEx :: Int
minEx@(I# me# :: Int#
me#) mantDigs :: Int
mantDigs@(I# md# :: Int#
md#) n :: Integer
n d :: Integer
d =
case Integer -> (# Int#, Int# #)
integerLog2IsPowerOf2# Integer
d of
(# ld# :: Int#
ld#, pw# :: Int#
pw# #)
| Int# -> Bool
isTrue# (Int#
pw# Int# -> Int# -> Int#
==# 0#) ->
case Integer -> Int#
integerLog2# Integer
n of
ln# :: Int#
ln# | Int# -> Bool
isTrue# (Int#
ln# Int# -> Int# -> Int#
>=# (Int#
ld# Int# -> Int# -> Int#
+# Int#
me# Int# -> Int# -> Int#
-# 1#)) ->
if Int# -> Bool
isTrue# (Int#
ln# Int# -> Int# -> Int#
<# Int#
md#)
then Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
n (Int# -> Int
I# (Int# -> Int#
negateInt# Int#
ld#))
else let n' :: Integer
n' = Integer
n Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftR` (Int# -> Int
I# (Int#
ln# Int# -> Int# -> Int#
+# 1# Int# -> Int# -> Int#
-# Int#
md#))
n'' :: Integer
n'' = case Integer -> Int# -> Int#
roundingMode# Integer
n (Int#
ln# Int# -> Int# -> Int#
-# Int#
md#) of
0# -> Integer
n'
2# -> Integer
n' Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ 1
_ -> case Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
n' Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. (1 :: Int) of
0 -> Integer
n'
_ -> Integer
n' Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ 1
in Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
n'' (Int# -> Int
I# (Int#
ln# Int# -> Int# -> Int#
-# Int#
ld# Int# -> Int# -> Int#
+# 1# Int# -> Int# -> Int#
-# Int#
md#))
| Bool
otherwise ->
case Int#
ld# Int# -> Int# -> Int#
+# (Int#
me# Int# -> Int# -> Int#
-# Int#
md#) of
ld'# :: Int#
ld'# | Int# -> Bool
isTrue# (Int#
ld'# Int# -> Int# -> Int#
<=# 0#) ->
Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
n (Int# -> Int
I# ((Int#
me# Int# -> Int# -> Int#
-# Int#
md#) Int# -> Int# -> Int#
-# Int#
ld'#))
| Int# -> Bool
isTrue# (Int#
ld'# Int# -> Int# -> Int#
<=# Int#
ln#) ->
let n' :: Integer
n' = Integer
n Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftR` (Int# -> Int
I# Int#
ld'#)
in case Integer -> Int# -> Int#
roundingMode# Integer
n (Int#
ld'# Int# -> Int# -> Int#
-# 1#) of
0# -> Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
n' (Int
minEx Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mantDigs)
1# -> if Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
n' Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. (1 :: Int) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
then Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
n' (Int
minExInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
mantDigs)
else Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat (Integer
n' Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ 1) (Int
minExInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
mantDigs)
_ -> Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat (Integer
n' Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ 1) (Int
minExInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
mantDigs)
| Int# -> Bool
isTrue# (Int#
ld'# Int# -> Int# -> Int#
># (Int#
ln# Int# -> Int# -> Int#
+# 1#)) -> Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat 0 0
| Bool
otherwise ->
case Integer -> (# Int#, Int# #)
integerLog2IsPowerOf2# Integer
n of
(# _, 0# #) -> Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat 0 0
(# _, _ #) -> Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat 1 (Int
minEx Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mantDigs)
| Bool
otherwise ->
let ln :: Int
ln = Int# -> Int
I# (Integer -> Int#
integerLog2# Integer
n)
ld :: Int
ld = Int# -> Int
I# Int#
ld#
p0 :: Int
p0 = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
minEx (Int
ln Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
ld)
(n' :: Integer
n', d' :: Integer
d')
| Int
p0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
mantDigs = (Integer
n Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftL` (Int
mantDigs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
p0), Integer
d)
| Int
p0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
mantDigs = (Integer
n, Integer
d)
| Bool
otherwise = (Integer
n, Integer
d Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftL` (Int
p0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mantDigs))
scale :: a -> c -> c -> (a, c, c)
scale p :: a
p a :: c
a b :: c
b
| (c
b c -> Int -> c
forall a. Bits a => a -> Int -> a
`shiftL` Int
mantDigs) c -> c -> Bool
forall a. Ord a => a -> a -> Bool
<= c
a = (a
pa -> a -> a
forall a. Num a => a -> a -> a
+1, c
a, c
b c -> Int -> c
forall a. Bits a => a -> Int -> a
`shiftL` 1)
| Bool
otherwise = (a
p, c
a, c
b)
(p' :: Int
p', n'' :: Integer
n'', d'' :: Integer
d'') = Int -> Integer -> Integer -> (Int, Integer, Integer)
forall c a. (Ord c, Bits c, Num a) => a -> c -> c -> (a, c, c)
scale (Int
p0Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
mantDigs) Integer
n' Integer
d'
rdq :: Integer
rdq = case Integer
n'' Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
d'' of
(q :: Integer
q,r :: Integer
r) -> case Integer -> Integer -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Integer
r Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
`shiftL` 1) Integer
d'' of
LT -> Integer
q
EQ -> if Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
q Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. (1 :: Int) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
then Integer
q else Integer
qInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+1
GT -> Integer
qInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+1
in Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
rdq Int
p'
plusFloat, minusFloat, timesFloat, divideFloat :: Float -> Float -> Float
plusFloat :: Float -> Float -> Float
plusFloat (F# x :: Float#
x) (F# y :: Float#
y) = Float# -> Float
F# (Float# -> Float# -> Float#
plusFloat# Float#
x Float#
y)
minusFloat :: Float -> Float -> Float
minusFloat (F# x :: Float#
x) (F# y :: Float#
y) = Float# -> Float
F# (Float# -> Float# -> Float#
minusFloat# Float#
x Float#
y)
timesFloat :: Float -> Float -> Float
timesFloat (F# x :: Float#
x) (F# y :: Float#
y) = Float# -> Float
F# (Float# -> Float# -> Float#
timesFloat# Float#
x Float#
y)
divideFloat :: Float -> Float -> Float
divideFloat (F# x :: Float#
x) (F# y :: Float#
y) = Float# -> Float
F# (Float# -> Float# -> Float#
divideFloat# Float#
x Float#
y)
negateFloat :: Float -> Float
negateFloat :: Float -> Float
negateFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
negateFloat# Float#
x)
gtFloat, geFloat, ltFloat, leFloat :: Float -> Float -> Bool
gtFloat :: Float -> Float -> Bool
gtFloat (F# x :: Float#
x) (F# y :: Float#
y) = Int# -> Bool
isTrue# (Float# -> Float# -> Int#
gtFloat# Float#
x Float#
y)
geFloat :: Float -> Float -> Bool
geFloat (F# x :: Float#
x) (F# y :: Float#
y) = Int# -> Bool
isTrue# (Float# -> Float# -> Int#
geFloat# Float#
x Float#
y)
ltFloat :: Float -> Float -> Bool
ltFloat (F# x :: Float#
x) (F# y :: Float#
y) = Int# -> Bool
isTrue# (Float# -> Float# -> Int#
ltFloat# Float#
x Float#
y)
leFloat :: Float -> Float -> Bool
leFloat (F# x :: Float#
x) (F# y :: Float#
y) = Int# -> Bool
isTrue# (Float# -> Float# -> Int#
leFloat# Float#
x Float#
y)
expFloat, logFloat, sqrtFloat, fabsFloat :: Float -> Float
sinFloat, cosFloat, tanFloat :: Float -> Float
asinFloat, acosFloat, atanFloat :: Float -> Float
sinhFloat, coshFloat, tanhFloat :: Float -> Float
asinhFloat, acoshFloat, atanhFloat :: Float -> Float
expFloat :: Float -> Float
expFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
expFloat# Float#
x)
logFloat :: Float -> Float
logFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
logFloat# Float#
x)
sqrtFloat :: Float -> Float
sqrtFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
sqrtFloat# Float#
x)
fabsFloat :: Float -> Float
fabsFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
fabsFloat# Float#
x)
sinFloat :: Float -> Float
sinFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
sinFloat# Float#
x)
cosFloat :: Float -> Float
cosFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
cosFloat# Float#
x)
tanFloat :: Float -> Float
tanFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
tanFloat# Float#
x)
asinFloat :: Float -> Float
asinFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
asinFloat# Float#
x)
acosFloat :: Float -> Float
acosFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
acosFloat# Float#
x)
atanFloat :: Float -> Float
atanFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
atanFloat# Float#
x)
sinhFloat :: Float -> Float
sinhFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
sinhFloat# Float#
x)
coshFloat :: Float -> Float
coshFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
coshFloat# Float#
x)
tanhFloat :: Float -> Float
tanhFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
tanhFloat# Float#
x)
asinhFloat :: Float -> Float
asinhFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
asinhFloat# Float#
x)
acoshFloat :: Float -> Float
acoshFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
acoshFloat# Float#
x)
atanhFloat :: Float -> Float
atanhFloat (F# x :: Float#
x) = Float# -> Float
F# (Float# -> Float#
atanhFloat# Float#
x)
powerFloat :: Float -> Float -> Float
powerFloat :: Float -> Float -> Float
powerFloat (F# x :: Float#
x) (F# y :: Float#
y) = Float# -> Float
F# (Float# -> Float# -> Float#
powerFloat# Float#
x Float#
y)
plusDouble, minusDouble, timesDouble, divideDouble :: Double -> Double -> Double
plusDouble :: Double -> Double -> Double
plusDouble (D# x :: Double#
x) (D# y :: Double#
y) = Double# -> Double
D# (Double#
x Double# -> Double# -> Double#
+## Double#
y)
minusDouble :: Double -> Double -> Double
minusDouble (D# x :: Double#
x) (D# y :: Double#
y) = Double# -> Double
D# (Double#
x Double# -> Double# -> Double#
-## Double#
y)
timesDouble :: Double -> Double -> Double
timesDouble (D# x :: Double#
x) (D# y :: Double#
y) = Double# -> Double
D# (Double#
x Double# -> Double# -> Double#
*## Double#
y)
divideDouble :: Double -> Double -> Double
divideDouble (D# x :: Double#
x) (D# y :: Double#
y) = Double# -> Double
D# (Double#
x Double# -> Double# -> Double#
/## Double#
y)
negateDouble :: Double -> Double
negateDouble :: Double -> Double
negateDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
negateDouble# Double#
x)
gtDouble, geDouble, leDouble, ltDouble :: Double -> Double -> Bool
gtDouble :: Double -> Double -> Bool
gtDouble (D# x :: Double#
x) (D# y :: Double#
y) = Int# -> Bool
isTrue# (Double#
x Double# -> Double# -> Int#
>## Double#
y)
geDouble :: Double -> Double -> Bool
geDouble (D# x :: Double#
x) (D# y :: Double#
y) = Int# -> Bool
isTrue# (Double#
x Double# -> Double# -> Int#
>=## Double#
y)
ltDouble :: Double -> Double -> Bool
ltDouble (D# x :: Double#
x) (D# y :: Double#
y) = Int# -> Bool
isTrue# (Double#
x Double# -> Double# -> Int#
<## Double#
y)
leDouble :: Double -> Double -> Bool
leDouble (D# x :: Double#
x) (D# y :: Double#
y) = Int# -> Bool
isTrue# (Double#
x Double# -> Double# -> Int#
<=## Double#
y)
double2Float :: Double -> Float
double2Float :: Double -> Float
double2Float (D# x :: Double#
x) = Float# -> Float
F# (Double# -> Float#
double2Float# Double#
x)
float2Double :: Float -> Double
float2Double :: Float -> Double
float2Double (F# x :: Float#
x) = Double# -> Double
D# (Float# -> Double#
float2Double# Float#
x)
expDouble, logDouble, sqrtDouble, fabsDouble :: Double -> Double
sinDouble, cosDouble, tanDouble :: Double -> Double
asinDouble, acosDouble, atanDouble :: Double -> Double
sinhDouble, coshDouble, tanhDouble :: Double -> Double
asinhDouble, acoshDouble, atanhDouble :: Double -> Double
expDouble :: Double -> Double
expDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
expDouble# Double#
x)
logDouble :: Double -> Double
logDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
logDouble# Double#
x)
sqrtDouble :: Double -> Double
sqrtDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
sqrtDouble# Double#
x)
fabsDouble :: Double -> Double
fabsDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
fabsDouble# Double#
x)
sinDouble :: Double -> Double
sinDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
sinDouble# Double#
x)
cosDouble :: Double -> Double
cosDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
cosDouble# Double#
x)
tanDouble :: Double -> Double
tanDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
tanDouble# Double#
x)
asinDouble :: Double -> Double
asinDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
asinDouble# Double#
x)
acosDouble :: Double -> Double
acosDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
acosDouble# Double#
x)
atanDouble :: Double -> Double
atanDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
atanDouble# Double#
x)
sinhDouble :: Double -> Double
sinhDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
sinhDouble# Double#
x)
coshDouble :: Double -> Double
coshDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
coshDouble# Double#
x)
tanhDouble :: Double -> Double
tanhDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
tanhDouble# Double#
x)
asinhDouble :: Double -> Double
asinhDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
asinhDouble# Double#
x)
acoshDouble :: Double -> Double
acoshDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
acoshDouble# Double#
x)
atanhDouble :: Double -> Double
atanhDouble (D# x :: Double#
x) = Double# -> Double
D# (Double# -> Double#
atanhDouble# Double#
x)
powerDouble :: Double -> Double -> Double
powerDouble :: Double -> Double -> Double
powerDouble (D# x :: Double#
x) (D# y :: Double#
y) = Double# -> Double
D# (Double#
x Double# -> Double# -> Double#
**## Double#
y)
foreign import ccall unsafe "isFloatNaN" isFloatNaN :: Float -> Int
foreign import ccall unsafe "isFloatInfinite" isFloatInfinite :: Float -> Int
foreign import ccall unsafe "isFloatDenormalized" isFloatDenormalized :: Float -> Int
foreign import ccall unsafe "isFloatNegativeZero" isFloatNegativeZero :: Float -> Int
foreign import ccall unsafe "isFloatFinite" isFloatFinite :: Float -> Int
foreign import ccall unsafe "isDoubleNaN" isDoubleNaN :: Double -> Int
foreign import ccall unsafe "isDoubleInfinite" isDoubleInfinite :: Double -> Int
foreign import ccall unsafe "isDoubleDenormalized" isDoubleDenormalized :: Double -> Int
foreign import ccall unsafe "isDoubleNegativeZero" isDoubleNegativeZero :: Double -> Int
foreign import ccall unsafe "isDoubleFinite" isDoubleFinite :: Double -> Int
foreign import capi unsafe "math.h log1p" log1pDouble :: Double -> Double
foreign import capi unsafe "math.h expm1" expm1Double :: Double -> Double
foreign import capi unsafe "math.h log1pf" log1pFloat :: Float -> Float
foreign import capi unsafe "math.h expm1f" expm1Float :: Float -> Float
word2Double :: Word -> Double
word2Double :: Word -> Double
word2Double (W# w :: Word#
w) = Double# -> Double
D# (Word# -> Double#
word2Double# Word#
w)
word2Float :: Word -> Float
word2Float :: Word -> Float
word2Float (W# w :: Word#
w) = Float# -> Float
F# (Word# -> Float#
word2Float# Word#
w)
{-# RULES
"fromIntegral/Int->Float" fromIntegral = int2Float
"fromIntegral/Int->Double" fromIntegral = int2Double
"fromIntegral/Word->Float" fromIntegral = word2Float
"fromIntegral/Word->Double" fromIntegral = word2Double
"realToFrac/Float->Float" realToFrac = id :: Float -> Float
"realToFrac/Float->Double" realToFrac = float2Double
"realToFrac/Double->Float" realToFrac = double2Float
"realToFrac/Double->Double" realToFrac = id :: Double -> Double
"realToFrac/Int->Double" realToFrac = int2Double -- See Note [realToFrac int-to-float]
"realToFrac/Int->Float" realToFrac = int2Float -- ..ditto
#-}
showSignedFloat :: (RealFloat a)
=> (a -> ShowS)
-> Int
-> a
-> ShowS
showSignedFloat :: (a -> ShowS) -> Int -> a -> ShowS
showSignedFloat showPos :: a -> ShowS
showPos p :: Int
p x :: a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x
= Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 6) (Char -> ShowS
showChar '-' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ShowS
showPos (-a
x))
| Bool
otherwise = a -> ShowS
showPos a
x
clamp :: Int -> Int -> Int
clamp :: Int -> Int -> Int
clamp bd :: Int
bd k :: Int
k = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max (-Int
bd) (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
bd Int
k)
{-# INLINE castWord32ToFloat #-}
castWord32ToFloat :: Word32 -> Float
castWord32ToFloat :: Word32 -> Float
castWord32ToFloat (W32# w# :: Word#
w#) = Float# -> Float
F# (Word# -> Float#
stgWord32ToFloat Word#
w#)
foreign import prim "stg_word32ToFloatzh"
stgWord32ToFloat :: Word# -> Float#
{-# INLINE castFloatToWord32 #-}
castFloatToWord32 :: Float -> Word32
castFloatToWord32 :: Float -> Word32
castFloatToWord32 (F# f# :: Float#
f#) = Word# -> Word32
W32# (Float# -> Word#
stgFloatToWord32 Float#
f#)
foreign import prim "stg_floatToWord32zh"
stgFloatToWord32 :: Float# -> Word#
{-# INLINE castWord64ToDouble #-}
castWord64ToDouble :: Word64 -> Double
castWord64ToDouble :: Word64 -> Double
castWord64ToDouble (W64# w :: Word#
w) = Double# -> Double
D# (Word# -> Double#
stgWord64ToDouble Word#
w)
foreign import prim "stg_word64ToDoublezh"
#if WORD_SIZE_IN_BITS == 64
stgWord64ToDouble :: Word# -> Double#
#else
stgWord64ToDouble :: Word64# -> Double#
#endif
{-# INLINE castDoubleToWord64 #-}
castDoubleToWord64 :: Double -> Word64
castDoubleToWord64 :: Double -> Word64
castDoubleToWord64 (D# d# :: Double#
d#) = Word# -> Word64
W64# (Double# -> Word#
stgDoubleToWord64 Double#
d#)
foreign import prim "stg_doubleToWord64zh"
#if WORD_SIZE_IN_BITS == 64
stgDoubleToWord64 :: Double# -> Word#
#else
stgDoubleToWord64 :: Double# -> Word64#
#endif