473,472 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

use math constants in visual c++. net 2003

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

Nov 17 '05 #1
1 3424
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.
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MLH | last post by:
I make API calls to the sndPlaySound function, something like this... XX% = sndPlaySound(msound, MyParm) Several predefined system constants (or API intrinsic constants) have been recommended...
1
by: Pawel | last post by:
How do you use a (pow) statement in visual c++.net 2003 standard edition? I want to calculate something and then display it to the user. But in a windows based enviornment not dos. What do you...
21
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c...
4
by: Jarod_24 | last post by:
I've managed find out how to start using the Win32 API's But some of these methods got constants that you should use when caling them. for example the LockSetForegroundWindow got a unsigned...
5
by: Tom Gurath | last post by:
http://osnews.com/story.php?news_id=5602&page=2 This benchmark tests the Math & File I/O of 9 languages/run-times. Visual C++ (Version 7 - not managed) Visual C# gcc C Visual Basic.NET Visual...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
6
by: PC | last post by:
Gentlesofts, Forgive me. I'm an abject newbie in your world, using VB 2005 with the dot-Net wonderfulness. So, I'm writing a wonderful class or two to interface with a solemnly ancient...
1
by: newscorrespondent | last post by:
Is there a way with Visual Studio 2003 and 2005 to list the name a value of compile time constants like those created with #define statements. Right now I have the need to use the same C# code in...
7
by: Chris Saunders | last post by:
I'm not very familiar with C#. I have a static class and would like to define some constants similarily to Math.PI. Could someone show me how to go about doing this. So far no luck searching. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.