Commits

Bryan O'Sullivan  committed 9af9d72

A few more little floating point cleanups.

  • Participants
  • Parent commits 02c12f4

Comments (0)

Files changed (1)

File Data/Aeson/Types.hs

     {-# INLINE toJSON #-}
 
 instance FromJSON Float where
-    parseJSON (Number n) = case n of
-                             D d -> pure . fromRational . toRational $ d
-                             I i -> pure (fromIntegral i)
+    parseJSON (Number n) = pure $ case n of
+                                    D d -> realToFrac d
+                                    I i -> fromIntegral i
     parseJSON Null       = pure (0/0)
     parseJSON v          = typeMismatch "Float" v
     {-# INLINE parseJSON #-}
     {-# INLINE toJSON #-}
 
 instance FromJSON (Ratio Integer) where
-    parseJSON (Number n) = case n of
-                             D d -> pure . toRational $ d
-                             I i -> pure (fromIntegral i)
+    parseJSON (Number n) = pure $ case n of
+                                    D d -> toRational d
+                                    I i -> fromIntegral i
     parseJSON v          = typeMismatch "Ratio Integer" v
     {-# INLINE parseJSON #-}