From 34502143d9c311fd06ed4ae180d59b45867a7faa Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 4 Nov 2017 15:34:14 -0700 Subject: [PATCH] Added float versions of SDL's math functions --- CMakeLists.txt | 6 +- configure | 31 ++++--- configure.in | 2 +- include/SDL_config.h.cmake | 15 +++- include/SDL_config.h.in | 15 +++- include/SDL_stdinc.h | 11 +++ src/dynapi/SDL_dynapi_overrides.h | 11 +++ src/dynapi/SDL_dynapi_procs.h | 11 +++ src/stdlib/SDL_stdlib.c | 130 +++++++++++++++++++++++++++--- 9 files changed, 203 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73d94077fb2f7..16141a51eb48b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -637,8 +637,10 @@ if(LIBC) wcslen wcscmp strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp - _stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos - cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf) + _stricmp _strnicmp sscanf + acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf + copysign copysignf cos cosf fabs fabsf floor floorf log logf + pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) string(TOUPPER ${_FN} _UPPER) set(HAVE_${_UPPER} 1) endforeach() diff --git a/configure b/configure index b622085ed5e99..02120e63806a9 100755 --- a/configure +++ b/configure @@ -16688,7 +16688,7 @@ if test "x$ac_cv_lib_m_pow" = xyes; then : LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm" fi - for ac_func in atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf + for ac_func in acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf fabs fabsf floor floorf log logf pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -21987,7 +21987,7 @@ CheckVulkan() { if test x$enable_video = xyes -a x$enable_video_vulkan = xyes; then case "$host" in - *-*-androideabi*) + *-*-android*) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -22515,7 +22515,7 @@ else fi case "$host" in - *-*-androideabi*) + *-*-android*) pthread_cflags="-D_REENTRANT -D_THREAD_SAFE" pthread_lib="" ;; @@ -23722,7 +23722,7 @@ CheckWarnAll case "$host" in *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*|*-*-nto*) case "$host" in - *-*-androideabi*) + *-*-android*) # Android ARCH=android ANDROID_CFLAGS="-DGL_GLEXT_PROTOTYPES" @@ -23867,17 +23867,24 @@ $as_echo "#define SDL_JOYSTICK_ANDROID 1" >>confdefs.h fi # Set up files for the haptic library if test x$enable_haptic = xyes; then - if test x$use_input_events = xyes; then - case $ARCH in - linux) + case $ARCH in + linux) + if test x$use_input_events = xyes; then $as_echo "#define SDL_HAPTIC_LINUX 1" >>confdefs.h - SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c" - have_haptic=yes - ;; - esac - fi + SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c" + have_haptic=yes + fi + ;; + android) + +$as_echo "#define SDL_HAPTIC_ANDROID 1" >>confdefs.h + + SOURCES="$SOURCES $srcdir/src/haptic/android/*.c" + have_haptic=yes + ;; + esac fi # Set up files for the power library if test x$enable_power = xyes; then diff --git a/configure.in b/configure.in index cd8116a3e0f2d..6ed312e36a7a5 100644 --- a/configure.in +++ b/configure.in @@ -271,7 +271,7 @@ if test x$enable_libc = xyes; then AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcscmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) - AC_CHECK_FUNCS(atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf) + AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf fabs fabsf floor floorf log logf pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) AC_CHECK_LIB(iconv, iconv_open, [LIBS="$LIBS -liconv"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -liconv"]) AC_CHECK_FUNCS(iconv) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 9b20398d0deab..56986e9f9517d 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -130,19 +130,30 @@ #cmakedefine HAVE_VSSCANF 1 #cmakedefine HAVE_VSNPRINTF 1 #cmakedefine HAVE_M_PI 1 -#cmakedefine HAVE_ATAN 1 -#cmakedefine HAVE_ATAN2 1 #cmakedefine HAVE_ACOS 1 +#cmakedefine HAVE_ACOSF 1 #cmakedefine HAVE_ASIN 1 +#cmakedefine HAVE_ASINF 1 +#cmakedefine HAVE_ATAN 1 +#cmakedefine HAVE_ATANF 1 +#cmakedefine HAVE_ATAN2 1 +#cmakedefine HAVE_ATAN2F 1 #cmakedefine HAVE_CEIL 1 +#cmakedefine HAVE_CEILF 1 #cmakedefine HAVE_COPYSIGN 1 +#cmakedefine HAVE_COPYSIGNF 1 #cmakedefine HAVE_COS 1 #cmakedefine HAVE_COSF 1 #cmakedefine HAVE_FABS 1 +#cmakedefine HAVE_FABSF 1 #cmakedefine HAVE_FLOOR 1 +#cmakedefine HAVE_FLOORF 1 #cmakedefine HAVE_LOG 1 +#cmakedefine HAVE_LOGF 1 #cmakedefine HAVE_POW 1 +#cmakedefine HAVE_POWF 1 #cmakedefine HAVE_SCALBN 1 +#cmakedefine HAVE_SCALBNF 1 #cmakedefine HAVE_SIN 1 #cmakedefine HAVE_SINF 1 #cmakedefine HAVE_SQRT 1 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 3655be67ca0d8..a87e275288e7d 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -135,19 +135,30 @@ #undef HAVE_SNPRINTF #undef HAVE_VSNPRINTF #undef HAVE_M_PI -#undef HAVE_ATAN -#undef HAVE_ATAN2 #undef HAVE_ACOS +#undef HAVE_ACOSF #undef HAVE_ASIN +#undef HAVE_ASINF +#undef HAVE_ATAN +#undef HAVE_ATANF +#undef HAVE_ATAN2 +#undef HAVE_ATAN2F #undef HAVE_CEIL +#undef HAVE_CEILF #undef HAVE_COPYSIGN +#undef HAVE_COPYSIGNF #undef HAVE_COS #undef HAVE_COSF #undef HAVE_FABS +#undef HAVE_FABSF #undef HAVE_FLOOR +#undef HAVE_FLOORF #undef HAVE_LOG +#undef HAVE_LOGF #undef HAVE_POW +#undef HAVE_POWF #undef HAVE_SCALBN +#undef HAVE_SCALBNF #undef HAVE_SIN #undef HAVE_SINF #undef HAVE_SQRT diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 72402299f2da1..115644d0de201 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -501,18 +501,29 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size #endif extern DECLSPEC double SDLCALL SDL_acos(double x); +extern DECLSPEC float SDLCALL SDL_acosf(float x); extern DECLSPEC double SDLCALL SDL_asin(double x); +extern DECLSPEC float SDLCALL SDL_asinf(float x); extern DECLSPEC double SDLCALL SDL_atan(double x); +extern DECLSPEC float SDLCALL SDL_atanf(float x); extern DECLSPEC double SDLCALL SDL_atan2(double x, double y); +extern DECLSPEC float SDLCALL SDL_atan2f(float x, float y); extern DECLSPEC double SDLCALL SDL_ceil(double x); +extern DECLSPEC float SDLCALL SDL_ceilf(float x); extern DECLSPEC double SDLCALL SDL_copysign(double x, double y); +extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y); extern DECLSPEC double SDLCALL SDL_cos(double x); extern DECLSPEC float SDLCALL SDL_cosf(float x); extern DECLSPEC double SDLCALL SDL_fabs(double x); +extern DECLSPEC float SDLCALL SDL_fabsf(float x); extern DECLSPEC double SDLCALL SDL_floor(double x); +extern DECLSPEC float SDLCALL SDL_floorf(float x); extern DECLSPEC double SDLCALL SDL_log(double x); +extern DECLSPEC float SDLCALL SDL_logf(float x); extern DECLSPEC double SDLCALL SDL_pow(double x, double y); +extern DECLSPEC float SDLCALL SDL_powf(float x, float y); extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n); +extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n); extern DECLSPEC double SDLCALL SDL_sin(double x); extern DECLSPEC float SDLCALL SDL_sinf(float x); extern DECLSPEC double SDLCALL SDL_sqrt(double x); diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index ac3980f5feab4..5467cb6e3d79a 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -647,3 +647,14 @@ #define SDL_AudioStreamAvailable SDL_AudioStreamAvailable_REAL #define SDL_FreeAudioStream SDL_FreeAudioStream_REAL #define SDL_AudioStreamFlush SDL_AudioStreamFlush_REAL +#define SDL_acosf SDL_acosf_REAL +#define SDL_asinf SDL_asinf_REAL +#define SDL_atanf SDL_atanf_REAL +#define SDL_atan2f SDL_atan2f_REAL +#define SDL_ceilf SDL_ceilf_REAL +#define SDL_copysignf SDL_copysignf_REAL +#define SDL_fabsf SDL_fabsf_REAL +#define SDL_floorf SDL_floorf_REAL +#define SDL_logf SDL_logf_REAL +#define SDL_powf SDL_powf_REAL +#define SDL_scalbnf SDL_scalbnf_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 8c0f8b7154dca..720bd92794305 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -681,3 +681,14 @@ SDL_DYNAPI_PROC(void,SDL_AudioStreamClear,(SDL_AudioStream *a),(a),) SDL_DYNAPI_PROC(int,SDL_AudioStreamAvailable,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(void,SDL_FreeAudioStream,(SDL_AudioStream *a),(a),) SDL_DYNAPI_PROC(int,SDL_AudioStreamFlush,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(float,SDL_acosf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_asinf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_atanf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_atan2f,(float a, float b),(a,b),return) +SDL_DYNAPI_PROC(float,SDL_ceilf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_copysignf,(float a, float b),(a,b),return) +SDL_DYNAPI_PROC(float,SDL_fabsf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_floorf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_logf,(float a),(a),return) +SDL_DYNAPI_PROC(float,SDL_powf,(float a, float b),(a,b),return) +SDL_DYNAPI_PROC(float,SDL_scalbnf,(float a, int b),(a,b),return) diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 36b5548571b0c..b0449eded491c 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -38,7 +38,17 @@ SDL_atan(double x) return atan(x); #else return SDL_uclibc_atan(x); -#endif /* HAVE_ATAN */ +#endif +} + +float +SDL_atanf(float x) +{ +#if defined(HAVE_ATANF) + return atanf(x); +#else + return (float)SDL_atan((double)x); +#endif } double @@ -48,7 +58,17 @@ SDL_atan2(double x, double y) return atan2(x, y); #else return SDL_uclibc_atan2(x, y); -#endif /* HAVE_ATAN2 */ +#endif +} + +float +SDL_atan2f(float x, float y) +{ +#if defined(HAVE_ATAN2F) + return atan2f(x, y); +#else + return (float)SDL_atan2((double)x, (double)y); +#endif } double @@ -71,6 +91,16 @@ SDL_acos(double val) #endif } +float +SDL_acosf(float val) +{ +#if defined(HAVE_ACOSF) + return acosf(val); +#else + return (float)SDL_acos((double)val); +#endif +} + double SDL_asin(double val) { @@ -87,6 +117,16 @@ SDL_asin(double val) #endif } +float +SDL_asinf(float val) +{ +#if defined(HAVE_ASINF) + return asinf(val); +#else + return (float)SDL_asin((double)val); +#endif +} + double SDL_ceil(double x) { @@ -102,6 +142,16 @@ SDL_ceil(double x) #endif /* HAVE_CEIL */ } +float +SDL_ceilf(float x) +{ +#if defined(HAVE_CEILF) + return ceilf(x); +#else + return (float)ceil((float)x); +#endif +} + double SDL_copysign(double x, double y) { @@ -120,6 +170,16 @@ SDL_copysign(double x, double y) #endif /* HAVE_COPYSIGN */ } +float +SDL_copysignf(float x, float y) +{ +#if defined(HAVE_COPYSIGNF) + return copysignf(x, y); +#else + return (float)SDL_copysign((double)x, (double)y); +#endif +} + double SDL_cos(double x) { @@ -127,7 +187,7 @@ SDL_cos(double x) return cos(x); #else return SDL_uclibc_cos(x); -#endif /* HAVE_COS */ +#endif } float @@ -147,7 +207,17 @@ SDL_fabs(double x) return fabs(x); #else return SDL_uclibc_fabs(x); -#endif /* HAVE_FABS */ +#endif +} + +float +SDL_fabsf(float x) +{ +#if defined(HAVE_FABSF) + return fabsf(x); +#else + return (float)SDL_fabs((double)x); +#endif } double @@ -157,7 +227,17 @@ SDL_floor(double x) return floor(x); #else return SDL_uclibc_floor(x); -#endif /* HAVE_FLOOR */ +#endif +} + +float +SDL_floorf(float x) +{ +#if defined(HAVE_FLOORF) + return floorf(x); +#else + return (float)SDL_floor((double)x); +#endif } double @@ -167,7 +247,17 @@ SDL_log(double x) return log(x); #else return SDL_uclibc_log(x); -#endif /* HAVE_LOG */ +#endif +} + +float +SDL_logf(float x) +{ +#if defined(HAVE_LOGF) + return logf(x); +#else + return (float)SDL_log((double)x); +#endif } double @@ -177,7 +267,17 @@ SDL_pow(double x, double y) return pow(x, y); #else return SDL_uclibc_pow(x, y); -#endif /* HAVE_POW */ +#endif +} + +float +SDL_powf(float x, float y) +{ +#if defined(HAVE_POWF) + return powf(x, y); +#else + return (float)SDL_pow((double)x, (double)y); +#endif } double @@ -193,7 +293,17 @@ SDL_scalbn(double x, int n) return ldexp(x, n); #else return SDL_uclibc_scalbn(x, n); -#endif /* HAVE_SCALBN */ +#endif +} + +float +SDL_scalbnf(float x, int n) +{ +#if defined(HAVE_SCALBNF) + return scalbnf(x, n); +#else + return (float)SDL_scalbn((double)x, n); +#endif } double @@ -203,7 +313,7 @@ SDL_sin(double x) return sin(x); #else return SDL_uclibc_sin(x); -#endif /* HAVE_SIN */ +#endif } float @@ -213,7 +323,7 @@ SDL_sinf(float x) return sinf(x); #else return (float)SDL_sin((double)x); -#endif /* HAVE_SINF */ +#endif } double