# Fabs and abs

in cint it seems that abs and fabs are different function

root [6] abs(1.2234234)
(const int)1
root [7] fabs(1.2234234)
(const double)1.22342339999999994e+00

but this is not the behaviour of c++

root [0] abs(1.2234234)
(const int)1
root [1] #include
root [2] abs(1.2234234)
(double)1.22342339999999994e+00

[quote=“Pepe Le Pew”]root [0] abs(1.2234234)
(const int)1
root [1] #include
root [2] abs(1.2234234)
(double)1.22342339999999994e+00[/quote]

Ok, but why it is not the default ?

[quote=“Pepe Le Pew”]man 3 abs
http://www.cplusplus.com/reference/clibrary/cstdlib/abs/
http://www.cplusplus.com/reference/clibrary/cmath/abs/
man 3 fabs
http://www.cplusplus.com/reference/clibrary/cmath/fabs/[/quote]

I dont’ understand. The point is that c++ abs is different from cint abs

Try simply this: [code]#if 1 /* 0 or 1 /
#include <stdlib.h> // for “abs”
#include <math.h> // for “fabs”
#else /
0 or 1 /
#include // for “std::abs” and “std::fabs”
#endif /
0 or 1 */

#include

using namespace std;

int main() {
cout << abs(1.123) << endl;
cout << fabs(1.123) << endl;
}[/code] and/or this: [code]#include <stdlib.h> // for “abs”
#include <math.h> // for “fabs”
#include // for “std::abs” and “std::fabs”

#include

int main() {
std::cout << abs(1.123) << std::endl;
std::cout << std::abs(1.123) << std::endl;
std::cout << fabs(1.123) << std::endl;
std::cout << std::fabs(1.123) << std::endl;
}[/code]

ok, but the point is: if cint is an interpreter of c++ why the default behaviour of cint is different than c++? Is it not more correct to have the same things behaving in the same way (without including anything)?

You should have got it by now that there’s no “default c++ behaviour” what concerns functions. You can define your own “abs” function which will do something completely different than the cmath’s “std::abs” and/or the stdlib’s “abs”, and that will be perfectly fine what concerns the “c++ standard”. Moreover, you will get the “std::abs” only if you "#include ", otherwise the compiler will exit with an error saying that “‘abs’ is not a member of ‘std’”. Likewise, if you do not “#include <stdlib.h>”, you will get an error saying that “‘abs’ was not declared in this scope”.

you are right. I dont know why on codepad (codepad.org/bzNr6Cxe) it works also without including the . In fact on my pc with gcc it doesn’t.

So now the question is: why cint knows abs? Probably because it automatically includes <stdlib.h>. So why don’t include automatically instead of <stdlib.h>?

CINT is an interpreter for C and C++ code (it actually started as a C interpreter, C++ support was added later). What you propose would severely break its C compatibility (and there would be no way to recover it).
So, if you want to use a particular function, make sure you #include an appropriate file (with this function’s prototype) in advance. No exceptions to this rule.