{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Numeric.Rounded.Hardware.Internal.Show where
import Data.Bifunctor (first)
import Data.Bits
import Data.Char (intToDigit)
import Numeric.Floating.IEEE.Internal (countTrailingZerosInteger)
import Numeric.Rounded.Hardware.Internal.Rounding
binaryFloatToDecimalDigitsRn :: forall a. RealFloat a
=> RoundingMode
-> Int
-> a
-> ([Int], Int)
binaryFloatToDecimalDigitsRn :: forall a. RealFloat a => RoundingMode -> Int -> a -> ([Int], Int)
binaryFloatToDecimalDigitsRn RoundingMode
_rm Int
_prec a
0 = ([], Int
0)
binaryFloatToDecimalDigitsRn RoundingMode
_rm Int
_prec a
x | forall a. RealFloat a => a -> Integer
floatRadix a
x forall a. Eq a => a -> a -> Bool
/= Integer
2 = forall a. HasCallStack => [Char] -> a
error [Char]
"radix must be 2"
binaryFloatToDecimalDigitsRn RoundingMode
rm Int
prec a
x =
let m :: Integer
n, d, e0 :: Int
(Integer
m,Int
n) = forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
d :: Int
d = forall a. RealFloat a => a -> Int
floatDigits a
x
e0 :: Int
e0 = forall a b. (RealFrac a, Integral b) => a -> b
floor (forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
d forall a. Num a => a -> a -> a
- Int
1 forall a. Num a => a -> a -> a
+ Int
n) forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a -> a
logBase a
10 a
2 :: a) forall a. Num a => a -> a -> a
- Int
prec
s, t :: Integer
(Integer
s,Integer
t) | Int
n forall a. Ord a => a -> a -> Bool
< Int
0, Int
0 forall a. Ord a => a -> a -> Bool
<= Int
e0 = (Integer
m, Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
n) forall a. Num a => a -> a -> a
* Integer
10forall a b. (Num a, Integral b) => a -> b -> a
^Int
e0)
| Int
0 forall a. Ord a => a -> a -> Bool
<= Int
e0 = (Integer
m forall a. Num a => a -> a -> a
* Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^Int
n, Integer
10forall a b. (Num a, Integral b) => a -> b -> a
^Int
e0)
| Int
n forall a. Ord a => a -> a -> Bool
< Int
0 = (Integer
m forall a. Num a => a -> a -> a
* Integer
10forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
e0), Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
n))
| Bool
otherwise = (Integer
m forall a. Num a => a -> a -> a
* Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^Int
n forall a. Num a => a -> a -> a
* Integer
10forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
e0), Integer
1)
q, r :: Integer
(Integer
q,Integer
r) = Integer
s forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
t
q', r', t' :: Integer
e' :: Int
(Integer
q',Integer
r',Integer
t',Int
e') | Integer
10forall a b. (Num a, Integral b) => a -> b -> a
^(Int
precforall a. Num a => a -> a -> a
+Int
1) forall a. Ord a => a -> a -> Bool
<= Integer
q = case Integer
q forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
10 of
(Integer
q'',Integer
r'') -> (Integer
q'', Integer
r''forall a. Num a => a -> a -> a
*Integer
tforall a. Num a => a -> a -> a
+Integer
r, Integer
10forall a. Num a => a -> a -> a
*Integer
t, Int
e0forall a. Num a => a -> a -> a
+Int
1)
| Bool
otherwise = (Integer
q,Integer
r,Integer
t,Int
e0)
in if Integer
r' forall a. Eq a => a -> a -> Bool
== Integer
0
then
Int -> Integer -> ([Int], Int)
loop0 Int
e' Integer
q'
else
case RoundingMode
rm of
RoundingMode
TowardNegInf -> Int -> Integer -> ([Int], Int)
loop0 Int
e' Integer
q'
RoundingMode
TowardZero -> Int -> Integer -> ([Int], Int)
loop0 Int
e' Integer
q'
RoundingMode
TowardInf -> Int -> Integer -> ([Int], Int)
loop0 Int
e' (Integer
q' forall a. Num a => a -> a -> a
+ Integer
1)
RoundingMode
ToNearest -> case forall a. Ord a => a -> a -> Ordering
compare (Integer
2 forall a. Num a => a -> a -> a
* Integer
r') Integer
t' of
Ordering
LT -> Int -> Integer -> ([Int], Int)
loop0 Int
e' Integer
q'
Ordering
EQ | forall a. Integral a => a -> Bool
even Integer
q' -> Int -> Integer -> ([Int], Int)
loop0 Int
e' Integer
q'
| Bool
otherwise -> Int -> Integer -> ([Int], Int)
loop0 Int
e' (Integer
q' forall a. Num a => a -> a -> a
+ Integer
1)
Ordering
GT -> Int -> Integer -> ([Int], Int)
loop0 Int
e' (Integer
q' forall a. Num a => a -> a -> a
+ Integer
1)
where
loop0 :: Int -> Integer -> ([Int], Int)
loop0 :: Int -> Integer -> ([Int], Int)
loop0 !Int
_ Integer
0 = ([], Int
0)
loop0 !Int
e Integer
a = case Integer
a forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
10 of
(Integer
q,Integer
0) -> Int -> Integer -> ([Int], Int)
loop0 (Int
eforall a. Num a => a -> a -> a
+Int
1) Integer
q
(Integer
q,Integer
r) -> Int -> [Int] -> Integer -> ([Int], Int)
loop (Int
eforall a. Num a => a -> a -> a
+Int
1) [forall a. Num a => Integer -> a
fromInteger Integer
r] Integer
q
loop :: Int -> [Int] -> Integer -> ([Int], Int)
loop :: Int -> [Int] -> Integer -> ([Int], Int)
loop !Int
e [Int]
acc Integer
0 = ([Int]
acc, Int
e)
loop !Int
e [Int]
acc Integer
a = case Integer
a forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
10 of
(Integer
q,Integer
r) -> Int -> [Int] -> Integer -> ([Int], Int)
loop (Int
eforall a. Num a => a -> a -> a
+Int
1) (forall a. Num a => Integer -> a
fromInteger Integer
r forall a. a -> [a] -> [a]
: [Int]
acc) Integer
q
{-# SPECIALIZE binaryFloatToDecimalDigitsRn :: RoundingMode -> Int -> Double -> ([Int], Int) #-}
binaryFloatToFixedDecimalDigitsRn :: forall a. RealFloat a
=> RoundingMode
-> Int
-> a
-> [Int]
binaryFloatToFixedDecimalDigitsRn :: forall a. RealFloat a => RoundingMode -> Int -> a -> [Int]
binaryFloatToFixedDecimalDigitsRn RoundingMode
_rm Int
_prec a
x | forall a. RealFloat a => a -> Integer
floatRadix a
x forall a. Eq a => a -> a -> Bool
/= Integer
2 = forall a. HasCallStack => [Char] -> a
error [Char]
"radix must be 2"
binaryFloatToFixedDecimalDigitsRn RoundingMode
rm Int
prec a
x =
let m, s, t, q, r :: Integer
e :: Int
(Integer
m,Int
e) = forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
(Integer
s,Integer
t) | Int
prec forall a. Ord a => a -> a -> Bool
>= Int
0, Int
e forall a. Num a => a -> a -> a
+ Int
prec forall a. Ord a => a -> a -> Bool
>= Int
0 = (Integer
m forall a. Num a => a -> a -> a
* Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(Int
eforall a. Num a => a -> a -> a
+Int
prec) forall a. Num a => a -> a -> a
* Integer
5forall a b. (Num a, Integral b) => a -> b -> a
^Int
prec, Integer
1)
| Int
prec forall a. Ord a => a -> a -> Bool
>= Int
0 = (Integer
m forall a. Num a => a -> a -> a
* Integer
5forall a b. (Num a, Integral b) => a -> b -> a
^Int
prec, Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
eforall a. Num a => a -> a -> a
-Int
prec))
| Int
e forall a. Num a => a -> a -> a
+ Int
prec forall a. Ord a => a -> a -> Bool
>= Int
0 = (Integer
m forall a. Num a => a -> a -> a
* Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(Int
eforall a. Num a => a -> a -> a
+Int
prec), Integer
5forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
prec))
| Bool
otherwise = (Integer
m, Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
eforall a. Num a => a -> a -> a
-Int
prec) forall a. Num a => a -> a -> a
* Integer
5forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
prec))
(Integer
q,Integer
r) = Integer
s forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
t
in if Integer
r forall a. Eq a => a -> a -> Bool
== Integer
0
then
[Int] -> Integer -> [Int]
loop [] Integer
q
else
case RoundingMode
rm of
RoundingMode
TowardNegInf -> [Int] -> Integer -> [Int]
loop [] Integer
q
RoundingMode
TowardZero -> [Int] -> Integer -> [Int]
loop [] Integer
q
RoundingMode
TowardInf -> [Int] -> Integer -> [Int]
loop [] (Integer
q forall a. Num a => a -> a -> a
+ Integer
1)
RoundingMode
ToNearest -> case forall a. Ord a => a -> a -> Ordering
compare (Integer
2 forall a. Num a => a -> a -> a
* Integer
r) Integer
t of
Ordering
LT -> [Int] -> Integer -> [Int]
loop [] Integer
q
Ordering
EQ | forall a. Integral a => a -> Bool
even Integer
q -> [Int] -> Integer -> [Int]
loop [] Integer
q
| Bool
otherwise -> [Int] -> Integer -> [Int]
loop [] (Integer
q forall a. Num a => a -> a -> a
+ Integer
1)
Ordering
GT -> [Int] -> Integer -> [Int]
loop [] (Integer
q forall a. Num a => a -> a -> a
+ Integer
1)
where
loop :: [Int] -> Integer -> [Int]
loop :: [Int] -> Integer -> [Int]
loop [Int]
acc Integer
0 = [Int]
acc
loop [Int]
acc Integer
a = case Integer
a forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
10 of
(Integer
q,Integer
r) -> [Int] -> Integer -> [Int]
loop (forall a. Num a => Integer -> a
fromInteger Integer
r forall a. a -> [a] -> [a]
: [Int]
acc) Integer
q
{-# SPECIALIZE binaryFloatToFixedDecimalDigitsRn :: RoundingMode -> Int -> Double -> [Int] #-}
binaryFloatToDecimalDigits :: RealFloat a
=> a
-> ([Int], Int)
binaryFloatToDecimalDigits :: forall a. RealFloat a => a -> ([Int], Int)
binaryFloatToDecimalDigits a
0 = ([], Int
0)
binaryFloatToDecimalDigits a
x | forall a. RealFloat a => a -> Integer
floatRadix a
x forall a. Eq a => a -> a -> Bool
/= Integer
2 = forall a. HasCallStack => [Char] -> a
error [Char]
"radix must be 2"
binaryFloatToDecimalDigits a
x =
let m, m', m'' :: Integer
n, z, n', e :: Int
(Integer
m,Int
n) = forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
x
z :: Int
z = Integer -> Int
countTrailingZerosInteger Integer
m
(Integer
m',Int
n') = (Integer
m forall a. Bits a => a -> Int -> a
`shiftR` Int
z, Int
n forall a. Num a => a -> a -> a
+ Int
z)
(Integer
m'',Int
e) | Int
n' forall a. Ord a => a -> a -> Bool
< Int
0 = (Integer
m' forall a. Num a => a -> a -> a
* Integer
5forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
n'), Int
n')
| Bool
otherwise = (Integer
m' forall a. Num a => a -> a -> a
* Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^Int
n', Int
0)
in Int -> Integer -> ([Int], Int)
loop0 Int
e Integer
m''
where
loop0 :: Int -> Integer -> ([Int], Int)
loop0 :: Int -> Integer -> ([Int], Int)
loop0 !Int
_ Integer
0 = ([Int
0], Int
0)
loop0 !Int
e Integer
a = case Integer
a forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
10 of
(Integer
q,Integer
0) -> Int -> Integer -> ([Int], Int)
loop0 (Int
eforall a. Num a => a -> a -> a
+Int
1) Integer
q
(Integer
q,Integer
r) -> Int -> [Int] -> Integer -> ([Int], Int)
loop (Int
eforall a. Num a => a -> a -> a
+Int
1) [forall a. Num a => Integer -> a
fromInteger Integer
r] Integer
q
loop :: Int -> [Int] -> Integer -> ([Int], Int)
loop :: Int -> [Int] -> Integer -> ([Int], Int)
loop !Int
e [Int]
acc Integer
0 = ([Int]
acc, Int
e)
loop !Int
e [Int]
acc Integer
n = case Integer
n forall a. Integral a => a -> a -> (a, a)
`quotRem` Integer
10 of
(Integer
q,Integer
r) -> Int -> [Int] -> Integer -> ([Int], Int)
loop (Int
eforall a. Num a => a -> a -> a
+Int
1) (forall a. Num a => Integer -> a
fromInteger Integer
r forall a. a -> [a] -> [a]
: [Int]
acc) Integer
q
{-# SPECIALIZE binaryFloatToDecimalDigits :: Double -> ([Int], Int) #-}
showEFloatRn :: RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showEFloatRn :: forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showEFloatRn RoundingMode
r Maybe Int
mprec a
x
| forall a. RealFloat a => a -> Bool
isNaN a
x = [Char] -> ShowS
showString [Char]
"NaN"
| a
x forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isNegativeZero a
x = Char -> ShowS
showChar Char
'-' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showEFloatRn (RoundingMode -> RoundingMode
oppositeRoundingMode RoundingMode
r) Maybe Int
mprec (-a
x)
| forall a. RealFloat a => a -> Bool
isInfinite a
x = [Char] -> ShowS
showString [Char]
"Infinity"
| Bool
otherwise = let ([Int]
xs,Int
e) = case Maybe Int
mprec of
Maybe Int
Nothing -> forall a. RealFloat a => a -> ([Int], Int)
binaryFloatToDecimalDigits a
x
Just Int
prec -> let !prec' :: Int
prec' = forall a. Ord a => a -> a -> a
max Int
prec Int
0
in forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (Int -> [Int] -> [Int]
padRight0 (Int
prec' forall a. Num a => a -> a -> a
+ Int
1)) forall a b. (a -> b) -> a -> b
$ forall a. RealFloat a => RoundingMode -> Int -> a -> ([Int], Int)
binaryFloatToDecimalDigitsRn RoundingMode
r Int
prec' a
x
e' :: Int
e' | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== Int
0) [Int]
xs = Int
0
| Bool
otherwise = Int
e forall a. Num a => a -> a -> a
- Int
1
in case [Int]
xs of
[] -> [Char] -> ShowS
showString [Char]
"0.0e0"
[Int
0] -> [Char] -> ShowS
showString [Char]
"0e0"
[Int
d] -> case Maybe Int
mprec of
Maybe Int
Nothing -> [Char] -> ShowS
showString forall a b. (a -> b) -> a -> b
$ Int -> Char
intToDigit Int
d forall a. a -> [a] -> [a]
: Char
'.' forall a. a -> [a] -> [a]
: Char
'0' forall a. a -> [a] -> [a]
: Char
'e' forall a. a -> [a] -> [a]
: forall a. Show a => a -> [Char]
show Int
e'
Maybe Int
_ -> [Char] -> ShowS
showString forall a b. (a -> b) -> a -> b
$ Int -> Char
intToDigit Int
d forall a. a -> [a] -> [a]
: Char
'e' forall a. a -> [a] -> [a]
: forall a. Show a => a -> [Char]
show Int
e'
(Int
d:[Int]
ds) -> [Char] -> ShowS
showString forall a b. (a -> b) -> a -> b
$ (Int -> Char
intToDigit Int
d forall a. a -> [a] -> [a]
: Char
'.' forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
ds) forall a. [a] -> [a] -> [a]
++ (Char
'e' forall a. a -> [a] -> [a]
: forall a. Show a => a -> [Char]
show Int
e')
where
padRight0 :: Int -> [Int] -> [Int]
padRight0 :: Int -> [Int] -> [Int]
padRight0 Int
0 [Int]
ys = [Int]
ys
padRight0 !Int
n [] = forall a. Int -> a -> [a]
replicate Int
n Int
0
padRight0 !Int
n (Int
y:[Int]
ys) = Int
y forall a. a -> [a] -> [a]
: Int -> [Int] -> [Int]
padRight0 (Int
n forall a. Num a => a -> a -> a
- Int
1) [Int]
ys
{-# SPECIALIZE showEFloatRn :: RoundingMode -> Maybe Int -> Double -> ShowS #-}
showFFloatRn :: RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showFFloatRn :: forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showFFloatRn RoundingMode
r Maybe Int
mprec a
x
| forall a. RealFloat a => a -> Bool
isNaN a
x = [Char] -> ShowS
showString [Char]
"NaN"
| a
x forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isNegativeZero a
x = Char -> ShowS
showChar Char
'-' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showFFloatRn (RoundingMode -> RoundingMode
oppositeRoundingMode RoundingMode
r) Maybe Int
mprec (-a
x)
| forall a. RealFloat a => a -> Bool
isInfinite a
x = [Char] -> ShowS
showString [Char]
"Infinity"
| Bool
otherwise = case Maybe Int
mprec of
Maybe Int
Nothing -> let ([Int]
xs,Int
e) = forall a. RealFloat a => a -> ([Int], Int)
binaryFloatToDecimalDigits a
x
l :: Int
l = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
xs
in if Int
e forall a. Ord a => a -> a -> Bool
>= Int
l then
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
xs then
[Char] -> ShowS
showString [Char]
"0.0"
else
[Char] -> ShowS
showString (forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
xs forall a. [a] -> [a] -> [a]
++ forall a. Int -> a -> [a]
replicate (Int
e forall a. Num a => a -> a -> a
- Int
l) Char
'0' forall a. [a] -> [a] -> [a]
++ [Char]
".0")
else
if Int
e forall a. Ord a => a -> a -> Bool
> Int
0 then
if Int
l forall a. Eq a => a -> a -> Bool
== Int
e then
[Char] -> ShowS
showString (forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
xs forall a. [a] -> [a] -> [a]
++ [Char]
".0")
else
let ([Int]
ys,[Int]
zs) = forall a. Int -> [a] -> ([a], [a])
splitAt Int
e [Int]
xs
ys' :: [Int]
ys' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
ys then [Int
0] else [Int]
ys
in [Char] -> ShowS
showString (forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
ys' forall a. [a] -> [a] -> [a]
++ [Char]
"." forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
zs)
else
[Char] -> ShowS
showString ([Char]
"0." forall a. [a] -> [a] -> [a]
++ forall a. Int -> a -> [a]
replicate (-Int
e) Char
'0' forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
xs)
Just Int
prec -> let prec' :: Int
prec' = forall a. Ord a => a -> a -> a
max Int
prec Int
0
xs :: [Int]
xs = forall a. RealFloat a => RoundingMode -> Int -> a -> [Int]
binaryFloatToFixedDecimalDigitsRn RoundingMode
r Int
prec' a
x
l :: Int
l = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
xs
in if Int
prec' forall a. Eq a => a -> a -> Bool
== Int
0 then
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
xs then
[Char] -> ShowS
showString [Char]
"0"
else
[Char] -> ShowS
showString forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
xs
else
if Int
l forall a. Ord a => a -> a -> Bool
<= Int
prec' then
[Char] -> ShowS
showString forall a b. (a -> b) -> a -> b
$ [Char]
"0." forall a. [a] -> [a] -> [a]
++ forall a. Int -> a -> [a]
replicate (Int
prec' forall a. Num a => a -> a -> a
- Int
l) Char
'0' forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
xs
else
let ([Int]
ys,[Int]
zs) = forall a. Int -> [a] -> ([a], [a])
splitAt (Int
l forall a. Num a => a -> a -> a
- Int
prec') [Int]
xs
ys' :: [Int]
ys' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
ys then [Int
0] else [Int]
ys
in [Char] -> ShowS
showString forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
ys' forall a. [a] -> [a] -> [a]
++ [Char]
"." forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
intToDigit [Int]
zs
{-# SPECIALIZE showFFloatRn :: RoundingMode -> Maybe Int -> Double -> ShowS #-}
showGFloatRn :: RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showGFloatRn :: forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showGFloatRn RoundingMode
r Maybe Int
mprec a
x | a
x forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
|| (a
0.1 forall a. Ord a => a -> a -> Bool
<= forall a. Num a => a -> a
abs a
x Bool -> Bool -> Bool
&& forall a. Num a => a -> a
abs a
x forall a. Ord a => a -> a -> Bool
< a
1e7) = forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showFFloatRn RoundingMode
r Maybe Int
mprec a
x
| Bool
otherwise = forall a. RealFloat a => RoundingMode -> Maybe Int -> a -> ShowS
showEFloatRn RoundingMode
r Maybe Int
mprec a
x
{-# SPECIALIZE showGFloatRn :: RoundingMode -> Maybe Int -> Double -> ShowS #-}