upiterbarg / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

Possible rounding bug in addition #160

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've been testing the new mpmath helper functions in gmpy, and I think I
encountered a rounding bug in mpmath 0.13.

>>> import mpmath.libmpf
>>> mmake = mpmath.libmpf.from_man_exp
>>> madd = mpmath.libmpf.mpf_add
>>> madd(mmake(9867,-100),mmake(-1,0),10,'d')
(1, mpz(1023), -10, 10)
>>> madd(mmake(9867,-200),mmake(-1,0),10,'d')
(1, mpz(1), 0, 1)
>>> 

Shouldn't the two results be the same?

Original issue reported on code.google.com by casevh on 10 Oct 2009 at 6:42

GoogleCodeExporter commented 9 years ago

Original comment by casevh on 10 Oct 2009 at 6:43

GoogleCodeExporter commented 9 years ago
Yes, definitely a bug.

Original comment by fredrik....@gmail.com on 10 Oct 2009 at 7:10

GoogleCodeExporter commented 9 years ago
In the code

    if tsign: sman -= 1

    else:     sman += 1

    if ssign: tman -= 1

    else:     tman += 1

i think it should check if ssign != tsign.

It would be nice to have a test function that automatically tries a lot of 
random
arguments with all rounding modes and programmatically verifies the rounding; it
would probably have revealed this a long time ago.

Original comment by fredrik....@gmail.com on 10 Oct 2009 at 7:21

GoogleCodeExporter commented 9 years ago
That fixes the issue. I'll extend the test programs I'm writing for the _mpmath_
routines to also test a large number of random values. I will be testing add, 
mult,
div, and sqrt.

Original comment by casevh on 11 Oct 2009 at 3:17

GoogleCodeExporter commented 9 years ago
Fixed in r991.

Original comment by Vinzent.Steinberg@gmail.com on 5 Nov 2009 at 11:26