Bug 1384480

Summary: Incorrect remainder calculation in gmpy2 using MPFR-3.1.4-1
Product: [Fedora] Fedora Reporter: spital <spital>
Component: mpfrAssignee: Frantisek Kluknavsky <fkluknav>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 24CC: fkluknav, rdieter
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: mpfr-3.1.5-1.fc24 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-10-28 19:51:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description spital 2016-10-13 11:23:17 UTC
Description of problem:

Assertion failed for

import gmpy2;x=14098670982472701L;mod=(2L**27-1);assert (x % mod) == gmpy2.remainder(x,mod)

Version-Release number of selected component (if applicable):
python2-gmpy2.x86_64                          2.0.8-1.fc24
mpfr-devel.x86_64                           3.1.4-1.fc24

How reproducible:

see description

Actual results:

assertion failed

Expected results:

passed

Additional info:

Please update to the latest upstream,
mpfr-3.1.5 with gmpy2-2.0.8 compiled from source works fine.

Comment 1 Fedora Update System 2016-10-14 04:55:48 UTC
mpfr-3.1.5-1.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-2a8c61e1cb

Comment 2 spital 2016-10-14 07:58:18 UTC
Did not work for me :

dnf remove python2-gmpy2 mpfr-devel

dnf --enablerepo=updates-testing --releasever=25 install python2-gmpy2-2.0.8-2.fc25 mpfr-devel-3.1.5-1.fc25

python

see OP

Comment 3 Frantisek Kluknavsky 2016-10-14 08:46:05 UTC
mpfr 3.1.5 for fedora 24 is on the way.

Comment 4 Fedora Update System 2016-10-14 21:23:48 UTC
mpfr-3.1.5-1.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-6c9d0d9a4f

Comment 5 Fedora Update System 2016-10-16 18:51:12 UTC
mpfr-3.1.5-1.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.

Comment 6 spital 2016-10-17 07:03:11 UTC
Still broken, I am thrilled with the quality assurance.

Please kindly try to run commands I posted.

https://bugzilla.redhat.com/show_bug.cgi?id=1384480#c2

Comment 7 Frantisek Kluknavsky 2016-10-17 14:24:13 UTC
gmpy2.remainder(gmpy2.mpfr('14098670982472701'),gmpy2.mpfr('134217727'))

-> mpfr('33159505.0')



with gmpy2.local_context(gmpy2.context(), precision=100) as ctx:
    gmpy2.remainder(gmpy2.mpfr('14098670982472701'),gmpy2.mpfr('134217727'))

-> mpfr('33159506.0',100)

Voila!

Please kindly think before you type and RTFM before you file a bug. Otherwise you only get ridiculed and your bug reports closed (sometimes even the meaningful ones once you build your reputation).
Try to file a bug against a correct component. If you think mpfr is buggy, prepare a reproducer using mpfr, not some weird wrapper library written in some funny language which even changes behavior of its division operator from time to time. 
Read some basics about floating point numbers, like https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf or https://people.eecs.berkeley.edu/~wkahan/
If your number exceeds approximately 2^50, you will get wrong results unless you do something with precision.
If you want quality assurance, pay for rhel.
And again, read the documentation before you file a bug.

Comment 8 Frantisek Kluknavsky 2016-10-17 14:40:36 UTC
echo 'scale=100;l(14098670982472701)/l(2)' | bc -l
-> 53.646...

Your number takes more than 53 bits. Setting 54 bits by gmpy2.local_context(gmpy2.context(), precision=54) is sufficient for a correct result, so I guess the computation done by mpfr is correct. If you think otherwise, please explain (of course I might be wrong).

Comment 9 Fedora Update System 2016-10-28 19:51:07 UTC
mpfr-3.1.5-1.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.