473,800 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ 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 3443
On Sun, 1 May 2005 20:50:01 -0700, "nvphu"
<nv***@discussi ons.microsoft.c om> 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_DEFIN ES 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_DEFIN ES
#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
4240
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 for use as the 2nd parm... SND_ASYNC
1
598
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 have to include and how? PG
21
2854
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 = 0, d = 0, e = 0; for(int n = 0; n != 6000000; n++) { a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2; b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2; c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
4
3678
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 integer as a parameter that either can be the value of "LSFW_LOCK" or "LSFW_UNLOCK" How do i get hold of these constants? Is there some <DllImport-thing that i can use to get hold of these constants?
5
1610
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 J# Java 1.3.1 Java 1.4.2
110
8627
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 almost halfway through writing the over 200 functions needed to implement C99's version of math.h, and I would like to have some feedback and/or expert advice on my implementations. Sincerely, Gregory Pietsch
6
3126
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 database. In times recently past, I would have done this with Borland Delphi. So, that's my perspective and I have my old Delphi code to crib from. That seems good.
1
1968
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 2003 and 2005 and need to know which version is doing the work. I could create one but if there is already one there I would rather use it. Thanks
7
2778
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. Regards Chris Saunders
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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 we have to send another system
2
3764
muto222
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.