This is a really simple question: Why are there predefined constants for pi, pi/2, pi/4, 1/pi and 2/pi but not for 2*pi? Is there a deeper reason behind it?
This question is not about the whole pi vs tau debate. I am wondering if there is a technical reason for implementing certain constants but not others. I can think of two possibilities:
[cmath] defines symbols in the std namespace, and may also define symbols in the global namespace. [math. h] defines symbols in the global namespace, and may also define symbols in the std namespace. if you include the former and use an unqualified symbol, it may compile with one compiler but not with another.
Using Constants in C: One is by using using the preprocessor directive '#define' to make 'PI' equal to 3.142857. The other uses the key work 'const' to define a double called 'pi' equal to 22.0/7.0.
Is 2*M_PI so hard to write?
Seriously though, once upon a time, when people worried about simple compilers that might not do constant folding and division was prohibitively expensive, it actually made sense to have a constant PI/2 rather than risk a runtime division. In our modern world, one would probably just define M_PI and call it a day, but the other variants live on for backwards compatibility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With