#identifier M_PI is undefined

32 messages · Page 1 of 1 (latest)

still rose
#

for some reason my program wont let me use my identifiers. They are defined in the header file and the .h is included in my cpp but it wont let me preform operations with them. Does anyone know why this might be? Ive never used these before so its most likely user error just cant figure it out.

amber crestBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

void axle
#

M_PI is not a standard thing

still rose
#

isnt it recognized as the value of pi

void axle
#

no

#

on some compilers yes

#

but it's non-standard

#

so you can't rely on it being there

#

i guess whatever compiler you're using atm doesn't define it

still rose
#

ohh, so whats the point of defining it at the top then

void axle
#

wdym

#

i don't see you define M_PI anywhere up there

still rose
#

ahhhh gotttt it

#

thank you!!

#

basically I have to define the value of pi as well

void axle
#

so thing it

#

you really shouldn't use #define for stuff like this

#

macros are really terrible

still rose
#

what would be better?

void axle
#

just make these constexpr variables

#

what compiler are you using?

still rose
#

so "const double pi=3.14"

#

?

void axle
#

for example

#

best make it constexpr, not just const

#

C++20 added standard math constants

#

so if you can use C++20, you can use std::numbers::pi_v<double>

#

#include <numbers>

still rose
#

Thank you!

void axle
#

np

amber crestBOT
#

@still rose Has your question been resolved? If so, run !solved :)

still rose
#

!solved