Bug with square roots
Emil Vladov
emil at emovla.com
Tue May 8 11:26:07 CEST 2012
Hi guys,
here's the information you have listed on the bug report page:
GMP version: 5.0.5
The program that follows takes sqrt of a long integer, then takes root(2). The resulting numbers are different (and both are wrong).
#include <gmp.h>
const char* N2 = "999999999543345433645659999999999999123156456489789789789564564231999999999999999999999945665544577654999999999999999999999994654987987564564231999999999999999999999";
#define PR(v) gmp_printf (#v " = %Zd\n", v);
int main(int argc, const char * argv[])
{
mpz_t N;
mpz_t sq;
mpz_t s1;
mpz_init (N);
mpz_init(sq);
mpz_init(s1);
mpz_set_str(N, N2, 10);
mpz_sqrt (sq, N);
mpz_root (s1, N, 2);
PR(sq);
PR(s1);
return 0;
}
Output from gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/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-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --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.9.00)
(this is what comes with XCode 4.3.2)
uname - a:
Darwin embp 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64
$ ./configfsf.guess
x86_64-apple-darwin11.3.0
$ ./config.guess
coreisbr-apple-darwin11.3.0
'make check' tests pass.
Please feel free to ask me if you need more details.
Cheers, Emil
More information about the gmp-bugs
mailing list