On Sun, 1 May 2005 20:50:01 -0700, "nvphu"
<nv***@discussions.microsoft.com> wrote:
I need to use the constant M_PI. So, I insert the directive # include <math.h>.
However when compiled, there are errors : M_PI undeclared identifier.
Second, I can not use the function round(double x).
Anyone could be so kind to help me.
Thanks a lot
From math.h:
"Define _USE_MATH_DEFINES before including math.h to expose these
macro definitions for common math constants. These are placed under
an #ifdef since these commonly-defined names are not part of the C/C++
standards."
So:
#define _USE_MATH_DEFINES
#include <math.h>
round() is not a C standard library function. You can create your own
simply:
double round(double x)
{
return floor(x + .5);
}
Or, if you always want to round toward zero:
double round(double x)
{
return x < 0 ? -floor(fabs(x) + .5) : floor(x + .5);
}
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.