-
March 28th, 2011, 01:06 PM
#1
valarray and math.h
Hi, I'm using valarray in my Visual C++ 2010 program. I'm also using two non-valarray math features. First is sqrt - not the one in valarray (its argument is a double not a valarray). I've included valarray header file in the program while I haven't included math.h. The compiler doesn't complain about sqrt and the program runs fine. Then I needed to use the constant M_PI which is defined in math.h. I thought since the compiler wasn't complaining about sqrt, it somehow included math.h, so I should be able to use M_PI. But I get an error for that. The compiler doesn't know M_PI. Is my assumption that math.h is included in my program correct? Is it possible that sqrt that I'm running comes from somewhere else (complex header file)? Do I need to define something else to enable using this constant even if math.h is included? May be the more important question is what's the relationship between valarray, math and complex? I would really appreciate your response. Thanks!
-
March 28th, 2011, 03:45 PM
#2
Re: valarray and math.h
I don't think that M_PI is standard C++. Try putting the following
at the top of your code (but after #include "stdafx.h")
Code:
#define _USE_MATH_DEFINES
-
March 28th, 2011, 04:52 PM
#3
Re: valarray and math.h
Thanks Philip for your reply. I did what you said but it didn't work. In math.h there's a comment saying that _USE_MATH_DEFINES must be defined before math.h. I defined it before including any other header file in my main C++ file but after stdafx (also before stdafx just for testing) to make sure that it is defined before math.h, and I still didn't get the result. I think I still need to play a bit more with this. Thanks again!
-
March 30th, 2011, 07:54 AM
#4
Re: valarray and math.h
Check if you are including math.h inside of stdafx.h.
If you are, you need to put the #define inside of stdafx.h, before including math.h. Otherwise any include of math.h after stdafx.h is ignored (as the file has already been included).
-
March 30th, 2011, 11:20 AM
#5
Re: valarray and math.h
You can do something like
Code:
#ifndef M_PI
#define M_PI 3.14159
#endif
in your own header file you want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|