fuzzylogician / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

gmpy2 2.0.0b1 on MacOS works incorrectly with pow() #54

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. install gmpy2 2.0.0b1 on Mac OS X. I've used virtualenv and installed gmpy2 
into a separate environment using pip;
2. see pow() produce incorrect result for mpz()'ed longs:

>>> pow(323947510405045044356526437872806578864909752L, 42348734, 
1340780792994259709957402499820584612747936582059239337772356L)
330141675879363806406773881742356491078431383556339984138544L

>>> pow(mpz(323947510405045044356526437872806578864909752L), mpz(42348734), 
mpz(1340780792994259709957402499820584612747936582059239337772356L))
mpz(1287392182932710257672876596597491822995237146669351591864552L)

While smaller numbers work OK:
>>> pow(62193873,42348734, 12387923)
3636582

>>> pow(mpz(62193873), mpz(42348734), mpz(12387923))
mpz(3636582)

What is the expected output? What do you see instead?

I would expect the pow() results to match (and they match on gmpy2 on Linux).

Original issue reported on code.google.com by anton.to...@gmail.com on 23 Apr 2012 at 7:45

GoogleCodeExporter commented 8 years ago
Thanks for the report. I don't have access to a Mac so I appreciate any help 
you can give me.

I'm guessing there is an issue with conversion to/from the C long type. Can you 
test with a range of sizes? I'd like to determine the size where failures begin.

What is the output of the following?

sys.int_info
gmpy2.mp_version()
gmpy2.mp_limbsize()

Original comment by casevh on 23 Apr 2012 at 4:44

GoogleCodeExporter commented 8 years ago
Hi!

I've got no sys.int_info as I am using python 2.6.8 rather than 3.1+.

>>> gmpy2.mp_version()
u'GMP 5.0.4'
>>> gmpy2.mp_limbsize()
64

I hope this helps.

Original comment by anton.to...@gmail.com on 4 May 2012 at 6:40

GoogleCodeExporter commented 8 years ago
What is the value of sys.maxint?

Does the test suite pass? (From the gmpy2 source directory, run "python 
test2/gmpy_test.py"

Original comment by casevh on 4 May 2012 at 1:02

GoogleCodeExporter commented 8 years ago
>>> sys.maxint
9223372036854775807

Test suite fails (please see output attached).

Original comment by anton.to...@gmail.com on 4 May 2012 at 1:22

Attachments:

GoogleCodeExporter commented 8 years ago
Are there error messages when gmpy2 is compiled?

Can you try downloading and compiling 1.15?

The first error message in gmpy2.test seems to imply a failure inside MPFR. Do 
GMP, MPFR, and MPC all pass their test suites (make check)?

I vaguely remember that (at least one of) GMP/MPFR/MPC don't like older 
versions of Xcode. Unfortunately, I have no idea what is considered old or new.

Original comment by casevh on 4 May 2012 at 8:14

GoogleCodeExporter commented 8 years ago
No, there are no error messages when gmpy2 is compiled. 1.15 produces no errors 
while compiling either, but fails the tests.

GMP tests went through fine, but MPFR tests failed. For example:

Error for mpfr_ui_pow(a, b, a) for b=1764214285 
a=1.10010010000111111011010101001e1
expected1.00011111011011011011010011100e92, got 
1.10000100011010001011111101100e87
FAIL: reuse

results differ for x=1.11001100001000101110010110101100001010000000000e-27 
prec=55 rnd_mode=MPFR_RNDN
got      1.100100011101111000010011110101010001100111011011001010
expected 1.100100011101111000010011111100011011011011001111000100
approx   0.11001000111011110000100111111000110110110110011110000111111001011E1
FAIL: tacos

So, this seems to be a bug in MPFR, right?

Original comment by anton.to...@gmail.com on 5 May 2012 at 7:38

GoogleCodeExporter commented 8 years ago
Based on comments on the GMP and MPFR mailing lists, some versions of Xcode 
have compiler bugs. Are you running the latest version of Xcode? If not, can 
you upgrade?

Original comment by casevh on 6 May 2012 at 4:19

GoogleCodeExporter commented 8 years ago
Just tried it and for me it worked.

(gmpy2)[last: 0] marca@scml-marca:~$ python
Python 2.6.1 (r261:67515, Aug  2 2010, 20:10:18) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> pow(323947510405045044356526437872806578864909752L, 42348734, 
1340780792994259709957402499820584612747936582059239337772356L)
330141675879363806406773881742356491078431383556339984138544L
>>> from gmpy2 import mpz
>>> pow(mpz(323947510405045044356526437872806578864909752L), mpz(42348734), 
mpz(1340780792994259709957402499820584612747936582059239337772356L))
mpz(330141675879363806406773881742356491078431383556339984138544L)
>>> pow(323947510405045044356526437872806578864909752L, 42348734, 
1340780792994259709957402499820584612747936582059239337772356L) == 
pow(mpz(323947510405045044356526437872806578864909752L), mpz(42348734), 
mpz(1340780792994259709957402499820584612747936582059239337772356L))
True

I'm on a MacBook Pro with OS X 10.6.8 (Snow Leopard) and Xcode Version 4.2 
(4C199) (Note that I have an older machine, also a MacBook Pro with OS X 
10.6.8, but which I believe has Xcode 3.2.x on it; I can try this later).

(gmpy2)[last: 0] marca@scml-marca:~$ gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.1~3/src/configure 
--disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 
--mandir=/share/man --enable-languages=c,objc,c++,obj-c++ 
--program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ 
--with-slibdir=/usr/lib --build=i686-apple-darwin10 
--enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.1~3/dst-llvmCore/Develop
er/usr/local --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 
--target=i686-apple-darwin10 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)

Here's how I installed mpfr (using 
[Homebrew](http://mxcl.github.com/homebrew/)):

(gmpy2)[last: 7] marca@scml-marca:~$ brew install mpfr
==> Downloading http://www.mpfr.org/mpfr-3.1.0/mpfr-3.1.0.tar.bz2
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file PATCHES
patching file VERSION
patching file src/mpfr-impl.h
patching file src/mpfr.h
patching file src/version.c
patching file PATCHES
patching file VERSION
patching file src/mpfr.h
patching file src/version.c
patching file tests/Makefile.am
patching file tests/Makefile.in
patching file PATCHES
patching file VERSION
patching file src/mpfr.h
patching file src/vasprintf.c
patching file src/version.c
patching file tests/tsprintf.c
patching file PATCHES
patching file VERSION
patching file doc/mpfr.info
patching file doc/mpfr.texi
patching file src/mpfr.h
patching file src/version.c
patching file tests/trandom.c
patching file tests/turandom.c
patching file PATCHES
patching file VERSION
patching file src/add_d.c
patching file src/add_ui.c
patching file src/mpfr.h
patching file src/mul_d.c
patching file src/version.c
patching file PATCHES
patching file VERSION
patching file src/mpfr-impl.h
patching file src/mpfr.h
patching file src/version.c
patching file PATCHES
patching file VERSION
patching file src/add1.c
patching file src/add1sp.c
patching file src/agm.c
patching file src/eq.c
patching file src/exp.c
patching file src/get_d.c
patching file src/get_flt.c
patching file src/get_str.c
patching file src/init2.c
patching file src/lngamma.c
patching file src/mpfr-impl.h
patching file src/mpfr.h
patching file src/mul.c
patching file src/pow.c
patching file src/print_raw.c
patching file src/round_prec.c
patching file src/round_raw_generic.c
patching file src/set.c
patching file src/set_f.c
patching file src/set_prec.c
patching file src/setmax.c
patching file src/sqr.c
patching file src/stack_interface.c
patching file src/strtofr.c
patching file src/sub1sp.c
patching file src/urandomb.c
patching file src/version.c
patching file tests/tinits.c
patching file PATCHES
patching file VERSION
patching file src/mpfr.h
patching file src/version.c
patching file PATCHES
patching file VERSION
patching file src/gamma.c
patching file src/mpfr.h
patching file src/version.c
patching file tests/tgamma.c
patching file PATCHES
patching file VERSION
patching file src/gamma.c
patching file src/lngamma.c
patching file src/mpfr.h
patching file src/version.c
patching file tests/tgamma.c
==> ./configure --prefix=/usr/local/Cellar/mpfr/3.1.0 
--build=x86_64-apple-darwin
==> make
==> make check
==> make install
/usr/local/Cellar/mpfr/3.1.0: 21 files, 3.1M, built in 66 seconds

Original comment by msabr...@gmail.com on 27 May 2012 at 2:32

GoogleCodeExporter commented 8 years ago
I just tried it on another machine and it worked there too. Again, this is OS X 
10.6.8 and I used mpfr from Homebrew. This machine has Xcode 3.2.6 (1761).

$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> pow(323947510405045044356526437872806578864909752L, 42348734, 
1340780792994259709957402499820584612747936582059239337772356L)
330141675879363806406773881742356491078431383556339984138544L
>>> from gmpy2 import mpz
>>> pow(mpz(323947510405045044356526437872806578864909752L), mpz(42348734), 
mpz(1340780792994259709957402499820584612747936582059239337772356L))
mpz(330141675879363806406773881742356491078431383556339984138544L)
>>> pow(323947510405045044356526437872806578864909752L, 42348734, 
1340780792994259709957402499820584612747936582059239337772356L) == 
pow(mpz(323947510405045044356526437872806578864909752L), mpz(42348734), 
mpz(1340780792994259709957402499820584612747936582059239337772356L))
True

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking 
--enable-werror --prefix=/usr --mandir=/share/man 
--enable-languages=c,objc,c++,obj-c++ 
--program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib 
--build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- 
--host=x86_64-apple-darwin10 --target=i686-apple-darwin10 
--with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)

Original comment by msabr...@gmail.com on 27 May 2012 at 5:19

GoogleCodeExporter commented 8 years ago
Thanks for testing. Since installation via Homebrew works, I'll close the 
ticket in a couple of days.

Original comment by casevh on 27 May 2012 at 5:53

GoogleCodeExporter commented 8 years ago
Marc, thanks again for testing. Closing this issue.

Original comment by casevh on 15 Jun 2012 at 6:24