News for hackers. Stuff that matters.
Re:How Many Decimals of Pi Do We Really Need? (2016) by taylodl on Monday September 28, 2020 @11:47AM (#24617907)
According to my numerical computing classes the best value of PI on your computing platform is:

atan(1.0) * 4

And if there's no math package on your system already defining PI then that's the value you should use - assuming there aren't legal requirements mandating other values to be used instead.

Re:How Many Decimals of Pi Do We Really Need? (2016) by daveFNbuck on Monday September 28, 2020 @12:07PM (#24618156)
Are there a lot of systems that define arctangent but not pi?
Re:How Many Decimals of Pi Do We Really Need? (2016) by kens on Monday September 28, 2020 @12:33PM (#24618438)
The cheap Sinclair Scientific calculator (1974) was rather primitive, so instead of storing constants internally, it printed constants such as e and pi on the case. The calculator was rather inaccurate, so you were much better off using 3.14159 from the case than computing 4×atan(1), which gave 3.1440.
Re:How Many Decimals of Pi Do We Really Need? (2016) by taylodl on Monday September 28, 2020 @12:50PM (#24618642)
It'd be interesting to see their implementation and the trade-offs its designers made.
Re:How Many Decimals of Pi Do We Really Need? (2016) by kens on Monday September 28, 2020 @01:24PM (#24619051)
I'm glad you asked :-) I reverse-engineered the Sinclair Scientific calculator, documented its code, and built a simulator: http://files.righto.com/calculator/sinclair_scientific_simul...

The short answer is that they used a 4-function calculator chip with just 320 words of ROM and managed to reprogram it into a cheap scientific calculator, a remarkable feat. The tradeoff was that the calculator was very slow and inaccurate.

Re:How Many Decimals of Pi Do We Really Need? (2016) by taylodl on Monday September 28, 2020 @01:47PM (#24619325)
That's amazing! Thank you for sharing!
Re:How Many Decimals of Pi Do We Really Need? (2016) by taylodl on Monday September 28, 2020 @12:43PM (#24618553)
C/C++ don't define PI but have an atan function. According to the TIOBE Index for September 2020 (https://www.tiobe.com/tiobe-index/) those languages are both in the top 5 of languages used by developers.
Re:How Many Decimals of Pi Do We Really Need? (2016) by votepaunchy on Monday September 28, 2020 @05:42PM (#24621525)
C++20 defines mathematical constants including Pi.

https://en.cppreference.com/w/cpp/numeric/constants

Re:How Many Decimals of Pi Do We Really Need? (2016) by taylodl on Tuesday September 29, 2020 @07:44AM (#24626478)
Thanks for the heads up! I haven't been paying any attention to C++20. You must be on the cutting edge of C++ to know that - I ended up having to work a bit on my Macbook Pro to get a version of gcc working that defines std::numbers::pi.
Re:How Many Decimals of Pi Do We Really Need? (2016) by saagarjha on Tuesday September 29, 2020 @01:52AM (#24624515)
They don’t but POSIX requires M_PI.
Re:How Many Decimals of Pi Do We Really Need? (2016) by xioxox on Tuesday September 29, 2020 @01:17AM (#24624371)
Yes - Fortan doesn't have a built-in pi constant, but does have trigonometric functions. Usually programs define pi based on atan or some other trig relation.
Re:How Many Decimals of Pi Do We Really Need? (2016) by gandalf013 on Monday September 28, 2020 @12:24PM (#24618350)
bc calculator doesn't (or didn't) define pi, but has atan. I've used "4*atan(1) method" in bc to get pi.
Re:How Many Decimals of Pi Do We Really Need? (2016) by ape4 on Monday September 28, 2020 @05:43PM (#24621534)
This works, `echo 'scale=100;4*a(1)' | bc -lq`
Re:How Many Decimals of Pi Do We Really Need? (2016) by srathi on Monday September 28, 2020 @10:22PM (#24623611)
I assume the later part of you comment refers to the (in)famous attempt by the Indiana state assembly to legalize Pi to be exactly equal to 3.
Re:How Many Decimals of Pi Do We Really Need? (2016) by taylodl on Tuesday September 29, 2020 @07:41AM (#24626455)
That thought had come across my mind, but no, I've seen engineering requirements stating something to the effect that the value of PI used in these calculations is to be 3.1415, for example.