Jump to content
  • Advertisement
Sign in to follow this  
frogtag

SOLVED - The Day The Math.h Died

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by frogtag
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?


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

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

[edit]

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

Share this post


Link to post
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 this post


Link to post
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++

[edit]

Edited for clarity.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
You should never use <math.h> 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 this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Quote:
Original post by jpetrie
You should never use <math.h> 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:2003

Annex D
(normative)
Compatibility features

  1. This clause describes features of the C++ Standard that are specified for compatibility with existing implementations.

  2. 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 headers
  1. For compatibility with the Standard C library, the C + + Standard library provides the 18 C headers, as shown in Table 100:

Table 100--C Headers

<assert.h> <iso646.h> <setjmp.h> <stdio.h> <wchar.h>
<ctype.h> <limits.h> <signal.h> <stdlib.h> <wctype.h>
<errno.h> <locale.h> <stdarg.h> <string.h>
<float.h> <math.h> <stddef.h> <time.h>



Red colored emphasis added.

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
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.


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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!