math library

Write here if you have problems with your C++ source code

Moderator: Board moderators

Ashique Mahmood Rupam
New poster
Posts: 8
Joined: Sun Sep 14, 2003 11:38 pm
Location: Dhaka
Contact:

reply

Post by Ashique Mahmood Rupam »

Thanks for the suggestion though knew it already. It is obvious that if a funciton is overloaded for some types and I am passing a value of other type, then I should type cast. But, I did not ask what I should do when I get this message.
I see that math functions of judge's compiler are overloaded ( when I use <cmath> ). Should they be ? As C math functions are inherited as they were, they should not have been overloaded as they were not. I do not also see any specification by TC++PL stroustrup. Then why are they overloaded ?
So, exactly what I want to know is why they overload them. Is there any standard indication for it, which I could not find yet. What I know is C++ math libraries should be kept as it is in C.
No, fun is meant.
There is Nothing, Nothing At All !
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

They were not overloaded because it's not possible in C. Three verions were present, but with different names. So float-sqrt was declared as sqrtf, long double-sqrt was declared as sqrtl and user had to choose the best version.
cmath receclares sqrt as:
[cpp] inline float
sqrt(float __x)
{ return __builtin_sqrtf(__x); }

inline long double
sqrt(long double __x)
{ return __builtin_sqrtl(__x); }[/cpp]
to make use of overloading mechanism.
Post Reply

Return to “C++”