libBF 0.6.7 → 0.6.8
raw patch · 5 files changed
+32/−3 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +7/−0
- libBF.cabal +1/−1
- src/LibBF.hs +2/−0
- src/LibBF/Mutable.hsc +10/−2
- tests/RunUnitTests.hs +12/−0
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Revision history for libBF-hs +## 0.6.8 -- 2024.06.05++* Fix a bug that would cause `(>)` and `(>=)` (in the `Ord BigFloat` instance)+ to return incorrect answers when one of the arguments is NaN.+* Fix a bug which could cause incorrect behavior (e.g., infinite loops) on+ 32-bit architectures.+ ## 0.6.7 -- 2023.11.28 * Add `Data` instances for `BigFloat`, `Sign`, `BFRep`, and `BFNum`.
libBF.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: libBF-version: 0.6.7+version: 0.6.8 synopsis: A binding to the libBF library. description: LibBF is a C library for working with arbitray precision IEEE 754 floating point numbers.
src/LibBF.hs view
@@ -158,6 +158,8 @@ instance Ord BigFloat where BigFloat x < BigFloat y = unsafe (cmpLT x y) BigFloat x <= BigFloat y = unsafe (cmpLEQ x y)+ BigFloat x > BigFloat y = unsafe (cmpLT y x)+ BigFloat x >= BigFloat y = unsafe (cmpLEQ y x) instance Hashable BigFloat where
src/LibBF/Mutable.hsc view
@@ -602,7 +602,7 @@ toRep = bf1 (\ptr -> do s <- #{peek bf_t, sign} ptr let sgn = if asBool s then Neg else Pos- e <- #{peek bf_t, expn} ptr+ e <- #{peek bf_t, expn} ptr :: IO SLimbT if | e == #{const BF_EXP_NAN} -> pure BFNaN | e == #{const BF_EXP_INF} -> pure (BFRep sgn Inf) | e == #{const BF_EXP_ZERO} -> pure (BFRep sgn Zero)@@ -618,9 +618,17 @@ base <- foldM step 0 (reverse (take len [ 0 .. ])) let bias = 64 * fromIntegral len++ -- `e :: SLimbT`, and we need it to be 64 bits in the code below.+ -- On 64-bit architectures, `SLimbT = Int64`, making this a+ -- no-op. On 32-bit architectures, `SLimbT = Int32`, so this code+ -- will extend `e` to 64 bits.+ eInt64 :: Int64+ eInt64 = fromIntegral e+ norm bs bi | even bs = norm (bs `shiftR` 1) (bi - 1)- | otherwise = BFRep sgn (Num bs (e - bi))+ | otherwise = BFRep sgn (Num bs (eInt64 - bi)) pure (norm base bias) -- (BFRep sgn (Num base (e - bias))) )
tests/RunUnitTests.hs view
@@ -34,6 +34,18 @@ , testGroup "bfIsSubnormal (float32 NearEven)" (map (\bf -> bfSubnormalTestCase bf False) [bfPosZero, bfFromInt 1, bfFromInt 0, bfNaN, bfNegInf, bfPosInf])+ , testGroup "IEEE 754 compare"+ [ testGroup "Comparisons with NaN should always return False"+ [ testCase "NaN > 0" $ False @=? bfNaN > bfPosZero+ , testCase "0 > NaN" $ False @=? bfPosZero > bfNaN+ , testCase "NaN >= 0" $ False @=? bfNaN >= bfPosZero+ , testCase "0 >= NaN" $ False @=? bfPosZero >= bfNaN+ , testCase "NaN < 0" $ False @=? bfNaN < bfPosZero+ , testCase "0 < NaN" $ False @=? bfPosZero < bfNaN+ , testCase "NaN <= 0" $ False @=? bfNaN <= bfPosZero+ , testCase "0 <= NaN" $ False @=? bfPosZero <= bfNaN+ ]+ ] ] statusUnderflow :: Status -> Bool