summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorBodigrim <andrew.lelechenko@gmail.com>2023-05-09 21:09:10 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-05-11 04:13:24 -0400
commit630b1fea1e41a1e00860a30742b6ab8ade8a0de0 (patch)
tree9694f4f4460253327c7ed7a1f75fe092a8f6e432 /libraries
parentbd0b056ea56643bcca1a23b78f72576f9459ce1b (diff)
downloadhaskell-630b1fea1e41a1e00860a30742b6ab8ade8a0de0.tar.gz
Document unlawfulness of instance Num Fixed
Fixes #22712
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/Data/Fixed.hs7
-rw-r--r--libraries/base/GHC/Float.hs4
2 files changed, 9 insertions, 2 deletions
diff --git a/libraries/base/Data/Fixed.hs b/libraries/base/Data/Fixed.hs
index bb45d20a38..a34f73ecd2 100644
--- a/libraries/base/Data/Fixed.hs
+++ b/libraries/base/Data/Fixed.hs
@@ -163,6 +163,13 @@ instance Enum (Fixed a) where
enumFromThenTo (MkFixed a) (MkFixed b) (MkFixed c) = fmap MkFixed (enumFromThenTo a b c)
-- | @since 2.01
+--
+-- Multiplication is not associative or distributive:
+--
+-- >>> (0.2 * 0.6 :: Deci) * 0.9 == 0.2 * (0.6 * 0.9)
+-- False
+-- >>> (0.1 + 0.1 :: Deci) * 0.5 == 0.1 * 0.5 + 0.1 * 0.5
+-- False
instance (HasResolution a) => Num (Fixed a) where
(MkFixed a) + (MkFixed b) = MkFixed (a + b)
(MkFixed a) - (MkFixed b) = MkFixed (a - b)
diff --git a/libraries/base/GHC/Float.hs b/libraries/base/GHC/Float.hs
index 195c23b1f4..8045216b25 100644
--- a/libraries/base/GHC/Float.hs
+++ b/libraries/base/GHC/Float.hs
@@ -279,7 +279,7 @@ class (RealFrac a, Floating a) => RealFloat a where
--
-- This instance implements IEEE 754 standard with all its usual pitfalls
-- about NaN, infinities and negative zero.
--- Neither addition not multiplication are associative or distributive:
+-- Neither addition nor multiplication are associative or distributive:
--
-- >>> (0.1 + 0.1 :: Float) + 0.5 == 0.1 + (0.1 + 0.5)
-- False
@@ -533,7 +533,7 @@ instance Show Float where
--
-- This instance implements IEEE 754 standard with all its usual pitfalls
-- about NaN, infinities and negative zero.
--- Neither addition not multiplication are associative or distributive:
+-- Neither addition nor multiplication are associative or distributive:
--
-- >>> (0.1 + 0.1) + 0.4 == 0.1 + (0.1 + 0.4)
-- False