2014-09-10 23:43:29 +08:00
|
|
|
/*
|
|
|
|
* There are multiple formulas for calculating arccosine of x:
|
|
|
|
* 1) acos(x) = (1/2*pi) + i * ln(i*x + sqrt(1-x^2)) (notice the 'i'...)
|
|
|
|
* 2) acos(x) = pi/2 + asin(-x) (asin isn't implemented yet)
|
|
|
|
* 3) acos(x) = pi/2 - asin(x) (ditto)
|
|
|
|
* 4) acos(x) = 2*atan2(sqrt(1-x), sqrt(1+x))
|
|
|
|
* 5) acos(x) = pi/2 - atan2(x, ( sqrt(1-x^2) ) )
|
|
|
|
*
|
|
|
|
* Options 1-3 are not currently usable, #5 generates more concise radeonsi
|
|
|
|
* bitcode and assembly than #4 (134 vs 132 instructions on radeonsi), but
|
|
|
|
* precision of #4 may be better.
|
|
|
|
*/
|
|
|
|
|
2015-04-25 03:54:17 +08:00
|
|
|
#if __CLC_FPSIZE == 32
|
|
|
|
#define __CLC_CONST(x) x ## f
|
|
|
|
#else
|
|
|
|
#define __CLC_CONST(x) x
|
|
|
|
#endif
|
|
|
|
|
2014-09-10 23:43:29 +08:00
|
|
|
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE acos(__CLC_GENTYPE x) {
|
|
|
|
return (
|
2015-04-25 03:54:17 +08:00
|
|
|
(__CLC_GENTYPE) __CLC_CONST(2.0) * atan2(
|
|
|
|
sqrt((__CLC_GENTYPE) __CLC_CONST(1.0) - x),
|
|
|
|
sqrt((__CLC_GENTYPE) __CLC_CONST(1.0) + x)
|
2014-09-10 23:43:29 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-04-25 03:54:17 +08:00
|
|
|
|
|
|
|
#undef __CLC_CONST
|