Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

use math constants in visual c++. net 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nvphu - 02 May 2005 04:50 GMT
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
Severian [MVP] - 02 May 2005 05:52 GMT
>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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.