Public Group

# SOLVED - The Day The Math.h Died

This topic is 3859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've recently switched from using Dev-C++ (a very very good program) to Visual C++ 2008 (also very good and now making me learn my c++ strictly). I'm shocked to find that VC++2008 doesn't come with a math.h header, what's up? Is the math.h header an unofficial header and so not included? or is VC++2008 just a little lacking in certain departments? Anyway, I'm trying to include PI for some equations ... which is the official header file to use?

##### Share on other sites
You should never use <math.h> in C++ -- you should have been using <cmath> The constant is also generally M_PI -- when it exists -- but this is an extension. C++ itself doesn't actually have this constant. For VS I believe you need to #define USE_MATH_DEFINES before #include <cmath> to enable them.

That said, you may just have your include paths set up incorrectly.

##### Share on other sites
Quote:
 Original post by frogtagI've recently switched from using Dev-C++ (a very very good program) to Visual C++ 2008 (also very good and now making me learn my c++ strictly). I'm shocked to find that VC++2008 doesn't come with a math.h header, what's up? Is the math.h header an unofficial header and so not included? or is VC++2008 just a little lacking in certain departments? Anyway, I'm trying to include PI for some equations ... which is the official header file to use?

Since math.h is a standard C header, it should be present.

It should be noted that in C++ you should #include <cmath> anyways

Did you write #include <Math.h> instead of #include <math.h> (lower case) ?

##### Share on other sites
As I've said VC++2008 is new to me and I'm a little confused between where the include files are stored, but I've found math.h in another location(!) ... but that said the info on cmath.h is really what i'm looking for. Thank You.

##### Share on other sites
Quote:
 Original post by frogtag cmath.h is really what i'm looking for. Thank You.

In C++ you're supposed to omit the ".h" on C++ standard headers, regardless of what the file is actually named in your filesystem. There is a historical reason for this and is defined by the specification.

You should just write:

#include <cmath> //C++

Edited for clarity.

##### Share on other sites
Quote:
 Original post by jpetrieYou should never use in C++

Unless you want the functions in the global namespace in addition to the std namespace, in which case you would use math.h.

##### Share on other sites
Quote:
Original post by SiCrane
Quote:
 Original post by jpetrieYou should never use in C++

Unless you want the functions in the global namespace in addition to the std namespace, in which case you would use math.h.

Erm,

Quote:
 From ISO/IEC 14882:2003Annex D(normative)Compatibility featuresThis clause describes features of the C++ Standard that are specified for compatibility with existing implementations.These are deprecated features, where deprecated is defined as: Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions....D.5 Standard C library headersFor compatibility with the Standard C library, the C + + Standard library provides the 18 C headers, as shown in Table 100:Table 100--C Headers

##### Share on other sites
Uh huh. Now give me a honest estimation of the probability that it would be removed from the standard anytime in the next 20 years, keeping in mind that doing so would effectively break millions of lines of existing code, not to mention future compatibility with header files for C libraries.

##### Share on other sites
Quote:
 Original post by SiCraneUh huh. Now give me a honest estimation of the probability that it would be removed from the standard anytime in the next 20 years, keeping in mind that doing so would effectively break millions of lines of existing code, not to mention future compatibility with header files for C libraries.

Pretty unlikely, but that's a poor excuse for using deprecated things for no other purpose than to shit all over the root namespace. I know a lot of code was broken when they yanked <conio.h> and company too!

##### Share on other sites
conio.h was never part of the C or C++ standard. math.h is part of both. And you're going to be stuck with the symbols in the global namespace either way since most major standard library implementations (e.g. gcc and MSVC) pull the symbols into both the root namespace and the std namespace when you include cmath anyways, and many programs written in C++ depend on that fact.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 44
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015720
×