creachadair / imath

Arbitrary precision integer and rational arithmetic library
Other
129 stars 20 forks source link

The pi example yields wrong results with more than 4095 digits #40

Closed motet-a closed 5 years ago

motet-a commented 5 years ago
$ ./pi 4095 10 | head -c 100
Computation took 0.03 sec.
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706
$ ./pi 4096 10 | head -c 100
Computation took 0.03 sec.
1.41592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067

$ uname -a
Darwin mba 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I will further investigate even if I’m not sure to find out what is causing the issue (I know almost nothing about computation of pi).

creachadair commented 5 years ago

I haven't looked at this code in a long time, but I think there's an upper bound to the number of digits you can get with Machin's formula, which is what that example uses. It's also entirely possible there are bugs, of course.

creachadair commented 5 years ago

Thank you for sending #41. I had some free time and wanted to resolve this, so I took over your change and submitted it as #42 with the suggestions from my comments. You can safely close your PR whenever you like.