Page 1 of 1

Having trouble with the PI number

Posted: January 15th, 2023, 10:49 pm
by feli_lecchini
I my code I include:

#define _USE_MATH_DEFINES
#include <cmath>

when I try to use M_PI (the macro that defines a double M_PI = 3.14....) it says "undefined symbol" or something like that. But when I use:

#define _USE_MATH_DEFINES
#include <math.h>

my code compiles without trouble. The problem is that the library <cmath> is recommended for C++ code while <math.h> is for C (something about cmath defining symbols inside the std namespace while math.h defines symbols in the global space).

Is there a way to work out this trouble ?...argg I hate macros with a passion, languages like C# and python are easier, they have abstract math classes with members (mathematical constants like PI and e) and methods (trigonometry, logarithms and other stuff) that are WAY MORE ORGANIZED that C++, but I want to master C++ with a passion too !

Re: Having trouble with the PI number

Posted: February 1st, 2023, 6:38 pm
by feli_lecchini
Any answer to this ?