From f242b37fab14c002374e7f7cc1cd43415edfc8d0 Mon Sep 17 00:00:00 2001 From: konsumlamm Date: Wed, 3 Jun 2026 10:54:37 +0200 Subject: [PATCH] Use IEEE754 encoding for `Float` and `Double` instances --- changelog.md | 1 + src/Data/Binary/Class.hs | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index cd1e2de..99d7850 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ binary-x.x.x.x TODO: fix since annotations +- Change `Binary` instances for `Float` and `Double` to use IEEE754 encoding. - Add `Data.Binary.Get.getShortByteString` - Don't reexport `Data.Word` from `Data.Binary` - Add `Binary (Proxy a)` instance diff --git a/src/Data/Binary/Class.hs b/src/Data/Binary/Class.hs index 577c460..17c4f4a 100644 --- a/src/Data/Binary/Class.hs +++ b/src/Data/Binary/Class.hs @@ -744,21 +744,15 @@ instance (Binary e) => Binary (Seq.Seq e) where ------------------------------------------------------------------------ -- Floating point --- | Uses non-IEEE754 encoding. Does not round-trip NaN. +-- | Uses IEEE754 encoding. instance Binary Double where - put d = put (decodeFloat d) - get = do - x <- get - y <- get - return $! encodeFloat x y + put = putDoublebe + get = getDoublebe --- | Uses non-IEEE754 encoding. Does not round-trip NaN. +-- | Uses IEEE754 encoding. instance Binary Float where - put f = put (decodeFloat f) - get = do - x <- get - y <- get - return $! encodeFloat x y + put = putFloatbe + get = getFloatbe ------------------------------------------------------------------------ -- Trees