|
6 | 6 | {-# LANGUAGE ExplicitForAll #-}
|
7 | 7 | {-# LANGUAGE ScopedTypeVariables #-}
|
8 | 8 | {-# LANGUAGE TypeApplications #-}
|
| 9 | +{-# LANGUAGE BlockArguments #-} |
9 | 10 | -- |
|
10 | 11 | -- Module : Data.ByteString.Builder.RealFloat
|
11 | 12 | -- Copyright : (c) Lawrence Wu 2021
|
@@ -246,18 +247,19 @@ formatFloating :: forall a mw ew ei.
|
246 | 247 | , R.FromInt ei
|
247 | 248 | ) => FloatFormat -> a -> Builder
|
248 | 249 | 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 |
250 | 251 | if e' >= minExpo && e' <= maxExpo
|
251 |
| - then printSign f `mappend` showStandard (toWord64 m) e' prec |
| 252 | + then std prec |
252 | 253 | 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 |
256 | 256 | where
|
257 | 257 | sci eE = BP.primBounded (R.toCharsScientific @a Proxy eE sign m e) ()
|
| 258 | + std prec = printSign f `mappend` showStandard (toWord64 m) e' prec |
258 | 259 | e' = R.toInt e + R.decimalLength m
|
259 | 260 | R.FloatingDecimal m e = toD @a mantissa expo
|
260 | 261 | (sign, mantissa, expo) = R.breakdown f
|
| 262 | + specialsOr ss = flip fromMaybe $ R.toCharsNonNumbersAndZero ss f |
261 | 263 |
|
262 | 264 | class ToWord64 a where toWord64 :: a -> Word64
|
263 | 265 | instance ToWord64 Word32 where toWord64 = R.word32ToWord64
|
|
0 commit comments