A bug with Sum (as in Monoid)

Lana Black lanablack at amok.cc
Wed Nov 6 22:30:34 UTC 2019


On 06/11/2019 22:19, Dannyu NDos wrote:
> Omg, addition is not even associative? The zeros truly ruined everything.
> 
> 2019년 11월 7일 (목) 06:58, Brent Yorgey <byorgey at gmail.com>님이 작성:
> 
>> How is that worse than the fact that addition is already not associative
>> for floating point types?  At least +0 is really the identity up to (==).
>>
>> On Wed, Nov 6, 2019, 3:49 PM Dannyu NDos <ndospark320 at gmail.com> wrote:
>>
>>> Sum has bug with floating points. Current definition states +0 as the
>>> identity element, while the actual identity is -0 since +0 + -0 = +0.
>>> _______________________________________________
>>> Libraries mailing list
>>> Libraries at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>
>>
> 
> 
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> 
This has little to do with zeroes per se. IEEE 754 addition isn't 
associative for any numbers, and examples not involving zeroes aren't 
hard to find. Here's one:

Prelude> let a = 1e30 :: Double
Prelude> let b = -1e30 :: Double
Prelude> let c = 1 :: Double
Prelude> a + b + c
1.0
Prelude> a + (b + c)
0.0

There is a good document describing how IEEE754 works, including this 
kind of peculiarities: 
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html


More information about the Libraries mailing list