Having trouble with the PI number

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
feli_lecchini
Posts: 15
Joined: November 7th, 2022, 12:58 am

Having trouble with the PI number

Post by feli_lecchini » January 15th, 2023, 10:49 pm

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 !

feli_lecchini
Posts: 15
Joined: November 7th, 2022, 12:58 am

Re: Having trouble with the PI number

Post by feli_lecchini » February 1st, 2023, 6:38 pm

Any answer to this ?

Post Reply