Sign in to follow this  
slanker70

cmath and math.h in Linux

Recommended Posts

Hi, I'm having problem regarding these 2 math functions using conde::BLocks in Linux: 1. acos 2. sqrt If I include math.h it coudn't find sqrt, and if I include cmath it says that acos is undefined. So I view the cmath header file and inside it includes math.h, but when I try to open math.h it says that file is not found. So ithink my math.h is missing in Linux. Can someone please help. Regards, Dana

Share this post


Link to post
Share on other sites
Remember that C++ is more strongly typed than C. C++ provides overloads of the trancendental functions for the various floating-point types in the std:: namespace. If you're using the C functions that appear in the :: namespace that happen to sneak in when you include <cmath> on C-based OSes like Linux, OS X, and most Unixes, you may not have the overloaded support.

For example, if you try to pass a float to ::acos(double) you will get an error. You should use ::acosf(float). On the other hand, C++ provides both std::acos(float) and std::acos(double), so things will just compile if you use the C++ standard library as documented.

There is a reason why C++ provides <cmath> instead of the <math.h> in the C standard library.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
if you try to pass a float to ::acos(double) you will get an error


Only when acos() is defined to take a reference, otherwise float can be implicitly converted to double. Apart from that, good post :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this