diff --git a/src/LibBF.hs b/src/LibBF.hs index 3ace56e..428cd4e 100644 --- a/src/LibBF.hs +++ b/src/LibBF.hs @@ -158,6 +158,8 @@ instance Eq BigFloat where 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 diff --git a/tests/RunUnitTests.hs b/tests/RunUnitTests.hs index 3e34d9e..8f54892 100644 --- a/tests/RunUnitTests.hs +++ b/tests/RunUnitTests.hs @@ -34,6 +34,18 @@ main = , 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