[Git][ghc/ghc][master] Document unlawfulness of instance Num Fixed

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Thu May 11 08:13:52 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
630b1fea by Bodigrim at 2023-05-11T04:13:24-04:00
Document unlawfulness of instance Num Fixed

Fixes #22712

- - - - -


2 changed files:

- libraries/base/Data/Fixed.hs
- libraries/base/GHC/Float.hs


Changes:

=====================================
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)


=====================================
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



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/630b1fea1e41a1e00860a30742b6ab8ade8a0de0

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/630b1fea1e41a1e00860a30742b6ab8ade8a0de0
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230511/c70f4339/attachment-0001.html>


More information about the ghc-commits mailing list