Should I use cmath to use PI and trig functions? I dont think math.h has it - and cmath and math seem like redefine alot of the same things.
What is standard practice?
Thanks,
Dave
Should I use cmath to use PI and trig functions? I dont think math.h has it - and cmath and math seem like redefine alot of the same things.
What is standard practice?
Thanks,
Dave
>What is standard practice?
Most people just define their own as needed:
const double PI = 3.141592;
M_PI used to be in "math.h". And it's still there.
>M_PI used to be in "math.h". And it's still there.
Only on your compiler. M_PI isn't a standard name.
so how do i make PI a standard name on my compiler? It doesn't seem to work with PI or M_PI if i include math.h and/or cmath.h
>so how do i make PI a standard name on my compiler?
Join the standardization committee and convince them to add it.
>It doesn't seem to work with PI or M_PI if i include math.h and/or cmath.h
Right, so look at my first reply and define it yourself.
Just to clarify if you need M_PI you usually need to do the following:
#define _USE_MATH_DEFINES
#include "math.h"
in that sequence!
then you get M_PI defined!
An alternative would be to use the c++ version
#define _USE_MATH_DEFINES
#include <cmath>
cheerz
Simple :
double const Pi=4*atan(1); // Pi=3.14
rgds
Dave
double const Pi=4*atan(1);
const double pi = boost::math::constants::pi<double>();
Try to see it in limits.h
COULD BE RIGHT COULD BE WRONG!
Try to see it in limits.h
It might be there, but if it is, it's a library extension unique to your compiler.
And if not, it would be good idea to have it, there are some constants that people use very often, so you cold try to writte them and then use them if you in need of it.
Well if you like to have fun, try to construct a array that will converge to it. Then use that number in that file if you really like to have a fun with programing, but most do have limits.h.
And if not, it would be good idea to have it, there are some constants that people use very often, so you cold try to writte them and then use them if you in need of it.
That's the approach I'd recommend. Create your own header with these things and reference it where needed. That way you don't depend on implementation-defined extensions.
but most do have limits.h
Everyone has that header, what I mean is that some variation of PI isn't a standard macro.
I don't know what you have ment, but this is it.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.