File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
tests/builder/Data/ByteString/Builder Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 7
7
{-# LANGUAGE ScopedTypeVariables #-}
8
8
{-# LANGUAGE TypeApplications #-}
9
9
{-# LANGUAGE BlockArguments #-}
10
+ {-# LANGUAGE NamedFieldPuns #-}
10
11
-- |
11
12
-- Module : Data.ByteString.Builder.RealFloat
12
13
-- Copyright : (c) Lawrence Wu 2021
@@ -81,6 +82,7 @@ module Data.ByteString.Builder.RealFloat
81
82
82
83
import Data.ByteString.Builder.Internal (Builder )
83
84
import qualified Data.ByteString.Builder.RealFloat.Internal as R
85
+ import Data.ByteString.Builder.RealFloat.Internal (positiveZero , negativeZero )
84
86
import qualified Data.ByteString.Builder.RealFloat.F2S as RF
85
87
import qualified Data.ByteString.Builder.RealFloat.D2S as RD
86
88
import qualified Data.ByteString.Builder.Prim as BP
@@ -132,7 +134,12 @@ fGeneric eE = FGeneric (R.asciiRaw $ ord eE)
132
134
--
133
135
-- @since 0.11.2.0
134
136
standard :: Int -> FloatFormat
135
- standard n = FStandard (Just n) standardSpecialStrings
137
+ standard n = FStandard (Just n) standardSpecialStrings {positiveZero, negativeZero}
138
+ where
139
+ positiveZero = if n == 0
140
+ then " 0"
141
+ else " 0." <> replicate n ' 0'
142
+ negativeZero = " -" <> positiveZero
136
143
137
144
-- | Standard notation with the \'default precision\' (decimal places matching `show`)
138
145
--
Original file line number Diff line number Diff line change @@ -799,7 +799,8 @@ testsFloating = testGroup "RealFloat"
799
799
singleMatches (formatDouble (standard 3 )) (flip (showFFloat (Just 3 )) [] ) ( 0.0096 , " 0.010" )
800
800
singleMatches (formatDouble (standard 5 )) (flip (showFFloat (Just 5 )) [] ) ( 12.345 , " 12.34500" )
801
801
singleMatches (formatDouble (standard 3 )) (flip (showFFloat (Just 3 )) [] ) ( 0.0 , " 0.000" )
802
- , testProperty " standard N" \ (NonNegative p, d :: Double ) -> (LC. unpack . toLazyByteString) (formatDouble (standard p) d) === showFFloat (Just p) d " "
802
+ , testProperty " standard N" \ (NonNegative p, d :: Double ) -> (LC. unpack . toLazyByteString)
803
+ (formatDouble (standard p) d) === showFFloat (Just p) d " "
803
804
]
804
805
, testMatches " d2sLooksLikePowerOf5" doubleDec show
805
806
[ ( (coerceWord64ToDouble 0x4830F0CF064DD592 ) , " 5.764607523034235e39" )
You can’t perform that action at this time.
0 commit comments