I've written a simple program in C++ to explain how the circumference of the circle being equal to 2*r*pi follows from the Pythagorean Theorem and numeric integration:

You ran that program with 10 mid points. Since there are an infinite number of mid points on any given circle, what happens if you run it with 10,000 mid points?

I get a not-a-number result because of numerical instability (dividing 0 by 0).

Interesting, because I got a number very close to pi.

Which compiler did you use? With what options? Results of fine numeric calculations can vary depending on which compiler and which options you use, as has been well-documented.

This one: https://www.onlinegdb.com/online_c++_compiler

If you're trying to do high precision calculations, then why wouldn't you choose high precision math options?

I ran his code on that site for 10 points and got this result:

*"The sum of the distances is 3.11865, which is close to but less than pi."*

Using 10,000 I got this:

*"The sum of the distances is 3.14159, which is close to but less than pi."*

No errors. Try it again? Maybe you made a mistake somewhere.

I tried it again, nope, it doesn't work for 10'000 points in CLANG. Well, this is slightly intriguing now. The

*double* type should be able to tell the difference between 0.9999 (=1-1/10000) and 1, it is supposed to be accurate to about 14 significant digits. No idea why it does not work in CLANG. On the other hand, OnlineGDB is even more precise than I would expect.

*3.14159* is correct to 5 decimal places, but for 10'000 points, it should only be correct for 4 of them. Maybe I will look into this more when I have time.

By the way, has anybody here written a math library? I've written some math functions for my programming language, you can read how I implemented the sine function here:

https://flatassembler.github.io/AEC_specification.html#Builtin