On Thu, Nov 18, 2010 at 8:20 PM, Neal Becker <ndbecker2@xxxxxxxxx> wrote: > cmath has patterns like this (taking cos as an example): > > using ::cos; > > inline float > cos(float __x) > { return __builtin_cosf(__x); } > > inline long double > cos(long double __x) > { return __builtin_cosl(__x); } > > template<typename _Tp> > inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, > double>::__type > cos(_Tp __x) > { return __builtin_cos(__x); } > > Do I understand correctly, that this means float, long double will use > __builtin_cos(xxx), but plain double will not use __builtin_cos??? > > I've tried tracing the generated code, and that's the way it looks. It > appears to just call the cos function in glibc. <cmath> is required to be compatible with <math.h> Most <math.h> come from the C compiler/library. So, plain cos() (for double) is whatever your C library provides. That is what the top using-declaration is all about. If you are using glibc, I believe it will ultimately use __builtin_cos unless you tell the compiler not to. > > Is this correct and if so, would not __builtin_cos be faster? > >