Check for and use copysignf

This commit is contained in:
Chris Robinson 2018-08-29 03:51:17 -07:00
parent 529f387695
commit 21dc2c761d
4 changed files with 18 additions and 1 deletions

View File

@ -536,6 +536,7 @@ CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF) CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F) CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F)
CHECK_SYMBOL_EXISTS(cbrtf math.h HAVE_CBRTF) CHECK_SYMBOL_EXISTS(cbrtf math.h HAVE_CBRTF)
CHECK_SYMBOL_EXISTS(copysignf math.h HAVE_COPYSIGNF)
IF(HAVE_FLOAT_H) IF(HAVE_FLOAT_H)
CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP) CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)

View File

@ -484,7 +484,7 @@ inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread,
*/ */
inline float ScaleAzimuthFront(float azimuth, float scale) inline float ScaleAzimuthFront(float azimuth, float scale)
{ {
ALfloat sign = (azimuth < 0.0f) ? -1.0f : 1.0f; ALfloat sign = copysignf(1.0f, azimuth);
if(!(fabsf(azimuth) > F_PI_2)) if(!(fabsf(azimuth) > F_PI_2))
return minf(fabsf(azimuth) * scale, F_PI_2) * sign; return minf(fabsf(azimuth) * scale, F_PI_2) * sign;
return azimuth; return azimuth;

View File

@ -40,6 +40,19 @@ static inline float cbrtf(float f)
} }
#endif #endif
#ifndef HAVE_COPYSIGNF
static inline float copysignf(float x, float y)
{
union {
float f;
unsigned int u;
} ux = { x }, uy = { y };
ux.u &= 0x7fffffffu;
ux.u |= (uy.u&0x80000000u);
return ux.f;
}
#endif
#define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0)) #define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0))
#define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI)) #define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI))

View File

@ -98,6 +98,9 @@
/* Define if we have the cbrtf function */ /* Define if we have the cbrtf function */
#cmakedefine HAVE_CBRTF #cmakedefine HAVE_CBRTF
/* Define if we have the copysignf function */
#cmakedefine HAVE_COPYSIGNF
/* Define if we have the strtof function */ /* Define if we have the strtof function */
#cmakedefine HAVE_STRTOF #cmakedefine HAVE_STRTOF