File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,7 @@ formatFloating :: forall a mw ew ei.
267
267
, R. ExponentBits a
268
268
, R. MantissaBits a
269
269
, R. CastToWord a
270
+ , R. MaxEncodedLength a
270
271
-- mantissa
271
272
, mw ~ R. MantissaWord a
272
273
, R. Mantissa mw
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ module Data.ByteString.Builder.RealFloat.Internal
44
44
, trimTrailing
45
45
, trimNoTrailing
46
46
, closestCorrectlyRounded
47
+ , MaxEncodedLength (.. )
47
48
, toCharsScientific
48
49
, asciiRaw
49
50
-- hand-rolled division and remainder for f2s and d2s
@@ -228,9 +229,9 @@ instance DecimalLength Word64 where decimalLength = decimalLength17
228
229
--
229
230
-- floats: 1 (sign) + 9 (mantissa) + 1 (.) + 1 (e) + 3 (exponent) = 15
230
231
-- doubles: 1 (sign) + 17 (mantissa) + 1 (.) + 1 (e) + 4 (exponent) = 24
231
- --
232
- maxEncodedLength :: Int
233
- maxEncodedLength = 32
232
+ class MaxEncodedLength a where maxEncodedLength :: Int
233
+ instance MaxEncodedLength Float where maxEncodedLength = 15
234
+ instance MaxEncodedLength Double where maxEncodedLength = 24
234
235
235
236
-- | Char7 encode a 'String'.
236
237
{-# INLINE string7 #-}
@@ -893,13 +894,14 @@ writeSign ptr False s = (# ptr, s #)
893
894
{-# SPECIALIZE toCharsScientific :: Proxy Float -> Word8# -> Bool -> Word32 -> Int32 -> BoundedPrim () #-}
894
895
{-# SPECIALIZE toCharsScientific :: Proxy Double -> Word8# -> Bool -> Word64 -> Int32 -> BoundedPrim () #-}
895
896
toCharsScientific :: forall a mw ei .
896
- ( Mantissa mw
897
+ ( MaxEncodedLength a
898
+ , Mantissa mw
897
899
, DecimalLength mw
898
900
, Integral ei
899
901
, ToInt ei
900
902
, FromInt ei
901
903
) => Proxy a -> Word8 # -> Bool -> mw -> ei -> BoundedPrim ()
902
- toCharsScientific _ eE ! sign ! mantissa ! expo = boundedPrim maxEncodedLength $ \ _ ! (Ptr p0)-> do
904
+ toCharsScientific _ eE ! sign ! mantissa ! expo = boundedPrim ( maxEncodedLength @ a ) $ \ _ ! (Ptr p0)-> do
903
905
let ! olength@ (I # ol) = decimalLength mantissa
904
906
! expo' = expo + fromInt olength - 1
905
907
IO $ \ s1 ->
You can’t perform that action at this time.
0 commit comments