L
Lodewijk Smit
Hi,
In the C standard of 1999 additional mathematical functions are added.
For example, beside the traditional
double sin(double x);
there are also the functions:
float sinf(float x);
long double sinl(long double x);
to compute the sin for respectively float and long double types.
However, most compilers do not implement all defined mathematical functions
in the standard. For example, the Intel 7.1 C compiler implements the float
version of sin (sinf), but has not the atan2f function. The gcc compiler
even not implements the sinf function.
It is simple to implement an own function for floats, e.g.
float mysinf(float x) {(float) return sin ((double) x);}
However, it is clear that this typecasted function is less efficient than a
dedicated sinf function. And maybe also not functional equivalent, because I
use a higher precision during the computation. Therefore, I would like to
use the dedicated sinf function if this is implemented by the compiler and
to use my own (not optimal) function otherwise. It is possible to implement
this behaviour by using #ifdef statements, but this is not prefered. In this
way I have to check all the mathematical functions that are used in my
program for every C compiler that can be used to compile my "standard" C
program.
Is it possible to check on compile time the namespace whether a sinf
function is included?
If this is possible, I can define my own sinf function if it is not in the
namespace and otherwise use the dedicated sinf function of the compiler.
Maybe there are also other known solutions to avoid this problem...
Any help is appreciated.
With kind regards,
Lodewijk
In the C standard of 1999 additional mathematical functions are added.
For example, beside the traditional
double sin(double x);
there are also the functions:
float sinf(float x);
long double sinl(long double x);
to compute the sin for respectively float and long double types.
However, most compilers do not implement all defined mathematical functions
in the standard. For example, the Intel 7.1 C compiler implements the float
version of sin (sinf), but has not the atan2f function. The gcc compiler
even not implements the sinf function.
It is simple to implement an own function for floats, e.g.
float mysinf(float x) {(float) return sin ((double) x);}
However, it is clear that this typecasted function is less efficient than a
dedicated sinf function. And maybe also not functional equivalent, because I
use a higher precision during the computation. Therefore, I would like to
use the dedicated sinf function if this is implemented by the compiler and
to use my own (not optimal) function otherwise. It is possible to implement
this behaviour by using #ifdef statements, but this is not prefered. In this
way I have to check all the mathematical functions that are used in my
program for every C compiler that can be used to compile my "standard" C
program.
Is it possible to check on compile time the namespace whether a sinf
function is included?
If this is possible, I can define my own sinf function if it is not in the
namespace and otherwise use the dedicated sinf function of the compiler.
Maybe there are also other known solutions to avoid this problem...
Any help is appreciated.
With kind regards,
Lodewijk