Defining M_PI in VS 2019?

I’m porting from Mac to PC, and am getting errors on the symbol M_PI, which is defined in <math.h>. It works on the Mac, but not on the PC. Looking into math.h, I see it relies on the macro _USE_MATH_DEFINES, which is apparently not defined for a Windows build. I can define it, but should I? Is there some other reason that this common math symbol is not getting defined? I see it also defined in JUCE’s compat.h, but that’s in the flac codec code, which I shouldn’t need.

What is the correct way to make sure that this is defined, when using JUCE on the PC?

Math Constants are not defined in Standard C/C++. To use them, you must first define _USE_MATH_DEFINES and then include cmath or math.h.


Any reason not to use juce::MathConstants<float>::pi instead?


I’m just porting someone else’s works, maybe he just didn’t know about that? I’ll ask him, thanks.

When in the same situation I add it to my StandardHeaders.h global header (where I also include any non-JUCE headers before JUCE’s headers)