on master help sign in
Use `truncate` instead of `floor` in Integral instances

Whether we should accept fractional parts at all is up to debate (#171). But rounding toward negative infinity is wrong either way. Truncation is the default in most languages, so it will cause the least surprise to users of the library.

commit014ab5612108c220f79f0b1ce67a5ae08f18c029 authorChris Wong <lambda.fairy@gmail.com> dateSat 11 Jul 2015, 11:42 (11 years ago) parent09b2ddc
1 file changed+2−2
Data/Aeson/Types/Instances.hs+2−2
Data/Aeson/Types/Instances.hs+2−2
@@ -311,7 +311,7 @@ instance ToJSON Integer where
311311-- specifying a scientific number with a big exponent like
312312-- @1e1000000000@.
313313instance FromJSON Integer where
314− parseJSON = withScientific "Integral" $ pure . floor
314+ parseJSON = withScientific "Integral" $ pure . truncate
315315 {-# INLINE parseJSON #-}
316316
317317instance ToJSON Int8 where
@@ -1614,5 +1614,5 @@ parseRealFloat expected v = typeMismatch expected v
16141614{-# INLINE parseRealFloat #-}
16151615
16161616parseIntegral :: Integral a => String -> Value -> Parser a
1617−parseIntegral expected = withScientific expected $ pure . floor
1617+parseIntegral expected = withScientific expected $ pure . truncate
16181618{-# INLINE parseIntegral #-}