05-31-2026 02:47 PM - edited 05-31-2026 02:50 PM
Over breakfast, I tweaked the code a little bit and this one does up to 7 numerator digits in a few milliseconds.
It does up to 10 numerator digits in a few seconds (each step takes about 10 longer), showing that for 9 or more digits, the rational approximation is identical to pi within DBL resolution. (e.g. for 9 digits: 245850922 / 78256779 == "piDBL")
Again, no guarantees. I am sure it can be improved... 😄
Looking at the "absolute difference" instead of "absolute (ratio-1)", but it makes no difference.
06-01-2026 03:36 AM
@altenbach wrote:
Cool!
Hey, this is 2026, so why not use a map instead of variant attributes?
On a side note, you could gain about 10-20% by just replacing the format into decimal string with a typecast. 😄
One flaw is that the third and fourth item have the same ratio
I'm just more used to Variant attributes, so instead of looking up how to to do it i went with Variants. The performance difference is very small. 🙂 I thought about Type cast but some test i did a long time ago showed surprisingly small difference, but my test might have been lacking.
Yes, i saw that the 3rd and 4th are the same, which in itself is interesting regarding which fractions do improve the result. That makes 355/113 even more impressive.