LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pi Approximation

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")

 

altenbach_0-1780256442976.png

 

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.

 

Message 11 of 12
(39 Views)

@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.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 12 of 12
(5 Views)