#define sqrtf sqrt
. Ed
> I am using the free C++ 5.5 compiler.
>
> When I compile I get :-
>
> Error E2268 C:\Program Files\DXSDK\include\d3dx8math.inl
> 1107 Call to undefined function 'sqrtf' in function
> D3DXVec2Length(const D3DXVECTOR2 *)
>I am using the free C++ 5.5 compiler.
>
>When I compile I get :-
>
>Error E2268 C:\Program Files\DXSDK\include\d3dx8math.inl 1107 Call to
>undefined function 'sqrtf' in function D3DXVec2Length(const D3DXVECTOR2 *)
[snip]
>
>sqrt and sqrtl are defined in C:\Program Files\Borland\BCC55\Include\math.h
>but sqrtf is not.
>
>Is there an alternative version of math.h that can be downloaded from
>borland which would include sqrtf ?
>
>Is there any other easy way of dealing with this problem ?
In C89, sqrt took a double argument and sqrtl for long double and
sqrtf for float - sqrtl and sqrtf were optional in C89 but now
required in C99. sqrtl and sqrtf are optional in C++
C++ is supposed to provide overloaded versions of sqrt when <cmath> is
included
float sqrt(float)
double sqrt(double)
long double sqrt(long double)
As you noted, BCPP 5.5 math.h does not provide sqrtf and cmath does
not provide all the overloads either - neither do some other
libraries.
For the following code, BCPP 5.5.1, Comeau/libcomo and MinGW/GCC 3.2
all get the same results - sqrt(double) is called in all cases. I
think BCB6 gets an ambiguity for the sqrt(int) (perhaps depending on
whether STLPORT library is used) because sqrt(float) and sqrt(double)
are equal matches. This is an issue for sin and cos etc as well and
under consideration by the C++ standards people I think.
#include <cmath>
#include <iostream>
void f1( float )
{
std::cout << "\nf1_float";
}
void f1( double )
{
std::cout << "\nf1_double";
}
void f1( long double )
{
std::cout << "\nf1_longdouble";
}
int main()
{
f1( sqrt(123.4f) );
f1( sqrt(123.4) );
f1( sqrt(123.4L) );
f1( sqrt(123) );
}
Graeme
The StlPort provided with BCB6 has sqrtf as a #define. It does not show up
in C++ code that does not use the STL or in C code.
. Ed