Skip to content

Commit 3612878

Browse files
cleaned up function formatFloating
1 parent 8081711 commit 3612878

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Data/ByteString/Builder/RealFloat.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# LANGUAGE ExplicitForAll #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
88
{-# LANGUAGE TypeApplications #-}
9+
{-# LANGUAGE BlockArguments #-}
910
-- |
1011
-- Module : Data.ByteString.Builder.RealFloat
1112
-- Copyright : (c) Lawrence Wu 2021
@@ -246,18 +247,19 @@ formatFloating :: forall a mw ew ei.
246247
, R.FromInt ei
247248
) => FloatFormat -> a -> Builder
248249
formatFloating fmt f = case fmt of
249-
FGeneric eE prec (minExpo,maxExpo) ss -> flip fromMaybe (R.toCharsNonNumbersAndZero ss f) $
250+
FGeneric eE prec (minExpo,maxExpo) ss -> specialsOr ss
250251
if e' >= minExpo && e' <= maxExpo
251-
then printSign f `mappend` showStandard (toWord64 m) e' prec
252+
then std prec
252253
else sci eE
253-
FScientific eE ss -> fromMaybe (sci eE) (R.toCharsNonNumbersAndZero ss f)
254-
FStandard prec ss -> flip fromMaybe (R.toCharsNonNumbersAndZero ss f) $
255-
printSign f `mappend` showStandard (toWord64 m) e' prec
254+
FScientific eE ss -> specialsOr ss $ sci eE
255+
FStandard prec ss -> specialsOr ss $ std prec
256256
where
257257
sci eE = BP.primBounded (R.toCharsScientific @a Proxy eE sign m e) ()
258+
std prec = printSign f `mappend` showStandard (toWord64 m) e' prec
258259
e' = R.toInt e + R.decimalLength m
259260
R.FloatingDecimal m e = toD @a mantissa expo
260261
(sign, mantissa, expo) = R.breakdown f
262+
specialsOr ss = flip fromMaybe $ R.toCharsNonNumbersAndZero ss f
261263

262264
class ToWord64 a where toWord64 :: a -> Word64
263265
instance ToWord64 Word32 where toWord64 = R.word32ToWord64

0 commit comments

Comments
 (0)