Added float versions of SDL's math functions
authorSam Lantinga <slouken@libsdl.org>
Sat, 04 Nov 2017 15:34:14 -0700
changeset 11682b26412a89fbb
parent 11679 d25d94d7dd86
child 11683 48bcba563d9c
Added float versions of SDL's math functions
CMakeLists.txt
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_stdinc.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/stdlib/SDL_stdlib.c
     1.1 --- a/CMakeLists.txt	Sat Nov 04 09:44:29 2017 -0700
     1.2 +++ b/CMakeLists.txt	Sat Nov 04 15:34:14 2017 -0700
     1.3 @@ -637,8 +637,10 @@
     1.4              wcslen wcscmp
     1.5              strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
     1.6              _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
     1.7 -            _stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos
     1.8 -            cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf)
     1.9 +            _stricmp _strnicmp sscanf
    1.10 +            acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
    1.11 +            copysign copysignf cos cosf fabs fabsf floor floorf log logf
    1.12 +            pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)
    1.13        string(TOUPPER ${_FN} _UPPER)
    1.14        set(HAVE_${_UPPER} 1)
    1.15      endforeach()
     2.1 --- a/configure	Sat Nov 04 09:44:29 2017 -0700
     2.2 +++ b/configure	Sat Nov 04 15:34:14 2017 -0700
     2.3 @@ -16688,7 +16688,7 @@
     2.4    LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"
     2.5  fi
     2.6  
     2.7 -    for ac_func in atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf
     2.8 +    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
     2.9  do :
    2.10    as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
    2.11  ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
    2.12 @@ -21987,7 +21987,7 @@
    2.13  {
    2.14      if test x$enable_video = xyes -a x$enable_video_vulkan = xyes; then
    2.15          case "$host" in
    2.16 -            *-*-androideabi*)
    2.17 +            *-*-android*)
    2.18                  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    2.19  /* end confdefs.h.  */
    2.20  
    2.21 @@ -22515,7 +22515,7 @@
    2.22  fi
    2.23  
    2.24      case "$host" in
    2.25 -         *-*-androideabi*)
    2.26 +         *-*-android*)
    2.27              pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
    2.28              pthread_lib=""
    2.29              ;;
    2.30 @@ -23722,7 +23722,7 @@
    2.31  case "$host" in
    2.32      *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*|*-*-nto*)
    2.33          case "$host" in
    2.34 -            *-*-androideabi*)
    2.35 +            *-*-android*)
    2.36                  # Android
    2.37                  ARCH=android
    2.38                  ANDROID_CFLAGS="-DGL_GLEXT_PROTOTYPES"
    2.39 @@ -23867,17 +23867,24 @@
    2.40          fi
    2.41          # Set up files for the haptic library
    2.42          if test x$enable_haptic = xyes; then
    2.43 -           if test x$use_input_events = xyes; then
    2.44 -             case $ARCH in
    2.45 -               linux)
    2.46 +          case $ARCH in
    2.47 +            linux)
    2.48 +                if test x$use_input_events = xyes; then
    2.49  
    2.50  $as_echo "#define SDL_HAPTIC_LINUX 1" >>confdefs.h
    2.51  
    2.52 -                   SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c"
    2.53 -                   have_haptic=yes
    2.54 -               ;;
    2.55 -             esac
    2.56 -           fi
    2.57 +                    SOURCES="$SOURCES $srcdir/src/haptic/linux/*.c"
    2.58 +                    have_haptic=yes
    2.59 +                fi
    2.60 +            ;;
    2.61 +            android)
    2.62 +
    2.63 +$as_echo "#define SDL_HAPTIC_ANDROID 1" >>confdefs.h
    2.64 +
    2.65 +                SOURCES="$SOURCES $srcdir/src/haptic/android/*.c"
    2.66 +                have_haptic=yes
    2.67 +            ;;
    2.68 +          esac
    2.69          fi
    2.70          # Set up files for the power library
    2.71          if test x$enable_power = xyes; then
     3.1 --- a/configure.in	Sat Nov 04 09:44:29 2017 -0700
     3.2 +++ b/configure.in	Sat Nov 04 15:34:14 2017 -0700
     3.3 @@ -271,7 +271,7 @@
     3.4      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)
     3.5  
     3.6      AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
     3.7 -    AC_CHECK_FUNCS(atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf)
     3.8 +    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)
     3.9  
    3.10      AC_CHECK_LIB(iconv, iconv_open, [LIBS="$LIBS -liconv"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -liconv"])
    3.11      AC_CHECK_FUNCS(iconv)
     4.1 --- a/include/SDL_config.h.cmake	Sat Nov 04 09:44:29 2017 -0700
     4.2 +++ b/include/SDL_config.h.cmake	Sat Nov 04 15:34:14 2017 -0700
     4.3 @@ -130,19 +130,30 @@
     4.4  #cmakedefine HAVE_VSSCANF 1
     4.5  #cmakedefine HAVE_VSNPRINTF 1
     4.6  #cmakedefine HAVE_M_PI 1
     4.7 +#cmakedefine HAVE_ACOS 1
     4.8 +#cmakedefine HAVE_ACOSF 1
     4.9 +#cmakedefine HAVE_ASIN 1
    4.10 +#cmakedefine HAVE_ASINF 1
    4.11  #cmakedefine HAVE_ATAN 1
    4.12 +#cmakedefine HAVE_ATANF 1
    4.13  #cmakedefine HAVE_ATAN2 1
    4.14 -#cmakedefine HAVE_ACOS 1
    4.15 -#cmakedefine HAVE_ASIN 1
    4.16 +#cmakedefine HAVE_ATAN2F 1
    4.17  #cmakedefine HAVE_CEIL 1
    4.18 +#cmakedefine HAVE_CEILF 1
    4.19  #cmakedefine HAVE_COPYSIGN 1
    4.20 +#cmakedefine HAVE_COPYSIGNF 1
    4.21  #cmakedefine HAVE_COS 1
    4.22  #cmakedefine HAVE_COSF 1
    4.23  #cmakedefine HAVE_FABS 1
    4.24 +#cmakedefine HAVE_FABSF 1
    4.25  #cmakedefine HAVE_FLOOR 1
    4.26 +#cmakedefine HAVE_FLOORF 1
    4.27  #cmakedefine HAVE_LOG 1
    4.28 +#cmakedefine HAVE_LOGF 1
    4.29  #cmakedefine HAVE_POW 1
    4.30 +#cmakedefine HAVE_POWF 1
    4.31  #cmakedefine HAVE_SCALBN 1
    4.32 +#cmakedefine HAVE_SCALBNF 1
    4.33  #cmakedefine HAVE_SIN 1
    4.34  #cmakedefine HAVE_SINF 1
    4.35  #cmakedefine HAVE_SQRT 1
     5.1 --- a/include/SDL_config.h.in	Sat Nov 04 09:44:29 2017 -0700
     5.2 +++ b/include/SDL_config.h.in	Sat Nov 04 15:34:14 2017 -0700
     5.3 @@ -135,19 +135,30 @@
     5.4  #undef HAVE_SNPRINTF
     5.5  #undef HAVE_VSNPRINTF
     5.6  #undef HAVE_M_PI
     5.7 +#undef HAVE_ACOS
     5.8 +#undef HAVE_ACOSF
     5.9 +#undef HAVE_ASIN
    5.10 +#undef HAVE_ASINF
    5.11  #undef HAVE_ATAN
    5.12 +#undef HAVE_ATANF
    5.13  #undef HAVE_ATAN2
    5.14 -#undef HAVE_ACOS
    5.15 -#undef HAVE_ASIN
    5.16 +#undef HAVE_ATAN2F
    5.17  #undef HAVE_CEIL
    5.18 +#undef HAVE_CEILF
    5.19  #undef HAVE_COPYSIGN
    5.20 +#undef HAVE_COPYSIGNF
    5.21  #undef HAVE_COS
    5.22  #undef HAVE_COSF
    5.23  #undef HAVE_FABS
    5.24 +#undef HAVE_FABSF
    5.25  #undef HAVE_FLOOR
    5.26 +#undef HAVE_FLOORF
    5.27  #undef HAVE_LOG
    5.28 +#undef HAVE_LOGF
    5.29  #undef HAVE_POW
    5.30 +#undef HAVE_POWF
    5.31  #undef HAVE_SCALBN
    5.32 +#undef HAVE_SCALBNF
    5.33  #undef HAVE_SIN
    5.34  #undef HAVE_SINF
    5.35  #undef HAVE_SQRT
     6.1 --- a/include/SDL_stdinc.h	Sat Nov 04 09:44:29 2017 -0700
     6.2 +++ b/include/SDL_stdinc.h	Sat Nov 04 15:34:14 2017 -0700
     6.3 @@ -501,18 +501,29 @@
     6.4  #endif
     6.5  
     6.6  extern DECLSPEC double SDLCALL SDL_acos(double x);
     6.7 +extern DECLSPEC float SDLCALL SDL_acosf(float x);
     6.8  extern DECLSPEC double SDLCALL SDL_asin(double x);
     6.9 +extern DECLSPEC float SDLCALL SDL_asinf(float x);
    6.10  extern DECLSPEC double SDLCALL SDL_atan(double x);
    6.11 +extern DECLSPEC float SDLCALL SDL_atanf(float x);
    6.12  extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
    6.13 +extern DECLSPEC float SDLCALL SDL_atan2f(float x, float y);
    6.14  extern DECLSPEC double SDLCALL SDL_ceil(double x);
    6.15 +extern DECLSPEC float SDLCALL SDL_ceilf(float x);
    6.16  extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
    6.17 +extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
    6.18  extern DECLSPEC double SDLCALL SDL_cos(double x);
    6.19  extern DECLSPEC float SDLCALL SDL_cosf(float x);
    6.20  extern DECLSPEC double SDLCALL SDL_fabs(double x);
    6.21 +extern DECLSPEC float SDLCALL SDL_fabsf(float x);
    6.22  extern DECLSPEC double SDLCALL SDL_floor(double x);
    6.23 +extern DECLSPEC float SDLCALL SDL_floorf(float x);
    6.24  extern DECLSPEC double SDLCALL SDL_log(double x);
    6.25 +extern DECLSPEC float SDLCALL SDL_logf(float x);
    6.26  extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
    6.27 +extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
    6.28  extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
    6.29 +extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
    6.30  extern DECLSPEC double SDLCALL SDL_sin(double x);
    6.31  extern DECLSPEC float SDLCALL SDL_sinf(float x);
    6.32  extern DECLSPEC double SDLCALL SDL_sqrt(double x);
     7.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Sat Nov 04 09:44:29 2017 -0700
     7.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Sat Nov 04 15:34:14 2017 -0700
     7.3 @@ -647,3 +647,14 @@
     7.4  #define SDL_AudioStreamAvailable SDL_AudioStreamAvailable_REAL
     7.5  #define SDL_FreeAudioStream SDL_FreeAudioStream_REAL
     7.6  #define SDL_AudioStreamFlush SDL_AudioStreamFlush_REAL
     7.7 +#define SDL_acosf SDL_acosf_REAL
     7.8 +#define SDL_asinf SDL_asinf_REAL
     7.9 +#define SDL_atanf SDL_atanf_REAL
    7.10 +#define SDL_atan2f SDL_atan2f_REAL
    7.11 +#define SDL_ceilf SDL_ceilf_REAL
    7.12 +#define SDL_copysignf SDL_copysignf_REAL
    7.13 +#define SDL_fabsf SDL_fabsf_REAL
    7.14 +#define SDL_floorf SDL_floorf_REAL
    7.15 +#define SDL_logf SDL_logf_REAL
    7.16 +#define SDL_powf SDL_powf_REAL
    7.17 +#define SDL_scalbnf SDL_scalbnf_REAL
     8.1 --- a/src/dynapi/SDL_dynapi_procs.h	Sat Nov 04 09:44:29 2017 -0700
     8.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Sat Nov 04 15:34:14 2017 -0700
     8.3 @@ -681,3 +681,14 @@
     8.4  SDL_DYNAPI_PROC(int,SDL_AudioStreamAvailable,(SDL_AudioStream *a),(a),return)
     8.5  SDL_DYNAPI_PROC(void,SDL_FreeAudioStream,(SDL_AudioStream *a),(a),)
     8.6  SDL_DYNAPI_PROC(int,SDL_AudioStreamFlush,(SDL_AudioStream *a),(a),return)
     8.7 +SDL_DYNAPI_PROC(float,SDL_acosf,(float a),(a),return)
     8.8 +SDL_DYNAPI_PROC(float,SDL_asinf,(float a),(a),return)
     8.9 +SDL_DYNAPI_PROC(float,SDL_atanf,(float a),(a),return)
    8.10 +SDL_DYNAPI_PROC(float,SDL_atan2f,(float a, float b),(a,b),return)
    8.11 +SDL_DYNAPI_PROC(float,SDL_ceilf,(float a),(a),return)
    8.12 +SDL_DYNAPI_PROC(float,SDL_copysignf,(float a, float b),(a,b),return)
    8.13 +SDL_DYNAPI_PROC(float,SDL_fabsf,(float a),(a),return)
    8.14 +SDL_DYNAPI_PROC(float,SDL_floorf,(float a),(a),return)
    8.15 +SDL_DYNAPI_PROC(float,SDL_logf,(float a),(a),return)
    8.16 +SDL_DYNAPI_PROC(float,SDL_powf,(float a, float b),(a,b),return)
    8.17 +SDL_DYNAPI_PROC(float,SDL_scalbnf,(float a, int b),(a,b),return)
     9.1 --- a/src/stdlib/SDL_stdlib.c	Sat Nov 04 09:44:29 2017 -0700
     9.2 +++ b/src/stdlib/SDL_stdlib.c	Sat Nov 04 15:34:14 2017 -0700
     9.3 @@ -38,7 +38,17 @@
     9.4      return atan(x);
     9.5  #else
     9.6      return SDL_uclibc_atan(x);
     9.7 -#endif /* HAVE_ATAN */
     9.8 +#endif
     9.9 +}
    9.10 +
    9.11 +float
    9.12 +SDL_atanf(float x)
    9.13 +{
    9.14 +#if defined(HAVE_ATANF)
    9.15 +    return atanf(x);
    9.16 +#else
    9.17 +    return (float)SDL_atan((double)x);
    9.18 +#endif
    9.19  }
    9.20  
    9.21  double
    9.22 @@ -48,7 +58,17 @@
    9.23      return atan2(x, y);
    9.24  #else
    9.25      return SDL_uclibc_atan2(x, y);
    9.26 -#endif /* HAVE_ATAN2 */
    9.27 +#endif
    9.28 +}
    9.29 +
    9.30 +float
    9.31 +SDL_atan2f(float x, float y)
    9.32 +{
    9.33 +#if defined(HAVE_ATAN2F)
    9.34 +    return atan2f(x, y);
    9.35 +#else
    9.36 +    return (float)SDL_atan2((double)x, (double)y);
    9.37 +#endif
    9.38  }
    9.39  
    9.40  double
    9.41 @@ -71,6 +91,16 @@
    9.42  #endif
    9.43  }
    9.44  
    9.45 +float
    9.46 +SDL_acosf(float val)
    9.47 +{
    9.48 +#if defined(HAVE_ACOSF)
    9.49 +    return acosf(val);
    9.50 +#else
    9.51 +    return (float)SDL_acos((double)val);
    9.52 +#endif
    9.53 +}
    9.54 +
    9.55  double
    9.56  SDL_asin(double val)
    9.57  {
    9.58 @@ -87,6 +117,16 @@
    9.59  #endif
    9.60  }
    9.61  
    9.62 +float
    9.63 +SDL_asinf(float val)
    9.64 +{
    9.65 +#if defined(HAVE_ASINF)
    9.66 +    return asinf(val);
    9.67 +#else
    9.68 +    return (float)SDL_asin((double)val);
    9.69 +#endif
    9.70 +}
    9.71 +
    9.72  double
    9.73  SDL_ceil(double x)
    9.74  {
    9.75 @@ -102,6 +142,16 @@
    9.76  #endif /* HAVE_CEIL */
    9.77  }
    9.78  
    9.79 +float
    9.80 +SDL_ceilf(float x)
    9.81 +{
    9.82 +#if defined(HAVE_CEILF)
    9.83 +    return ceilf(x);
    9.84 +#else
    9.85 +    return (float)ceil((float)x);
    9.86 +#endif
    9.87 +}
    9.88 +
    9.89  double
    9.90  SDL_copysign(double x, double y)
    9.91  {
    9.92 @@ -120,6 +170,16 @@
    9.93  #endif /* HAVE_COPYSIGN */
    9.94  }
    9.95  
    9.96 +float
    9.97 +SDL_copysignf(float x, float y)
    9.98 +{
    9.99 +#if defined(HAVE_COPYSIGNF)
   9.100 +    return copysignf(x, y);
   9.101 +#else
   9.102 +    return (float)SDL_copysign((double)x, (double)y);
   9.103 +#endif
   9.104 +}
   9.105 +
   9.106  double
   9.107  SDL_cos(double x)
   9.108  {
   9.109 @@ -127,7 +187,7 @@
   9.110      return cos(x);
   9.111  #else
   9.112      return SDL_uclibc_cos(x);
   9.113 -#endif /* HAVE_COS */
   9.114 +#endif
   9.115  }
   9.116  
   9.117  float
   9.118 @@ -147,7 +207,17 @@
   9.119      return fabs(x); 
   9.120  #else
   9.121      return SDL_uclibc_fabs(x);
   9.122 -#endif /* HAVE_FABS */
   9.123 +#endif
   9.124 +}
   9.125 +
   9.126 +float
   9.127 +SDL_fabsf(float x)
   9.128 +{
   9.129 +#if defined(HAVE_FABSF)
   9.130 +    return fabsf(x); 
   9.131 +#else
   9.132 +    return (float)SDL_fabs((double)x);
   9.133 +#endif
   9.134  }
   9.135  
   9.136  double
   9.137 @@ -157,7 +227,17 @@
   9.138      return floor(x);
   9.139  #else
   9.140      return SDL_uclibc_floor(x);
   9.141 -#endif /* HAVE_FLOOR */
   9.142 +#endif
   9.143 +}
   9.144 +
   9.145 +float
   9.146 +SDL_floorf(float x)
   9.147 +{
   9.148 +#if defined(HAVE_FLOORF)
   9.149 +    return floorf(x);
   9.150 +#else
   9.151 +    return (float)SDL_floor((double)x);
   9.152 +#endif
   9.153  }
   9.154  
   9.155  double
   9.156 @@ -167,7 +247,17 @@
   9.157      return log(x);
   9.158  #else
   9.159      return SDL_uclibc_log(x);
   9.160 -#endif /* HAVE_LOG */
   9.161 +#endif
   9.162 +}
   9.163 +
   9.164 +float
   9.165 +SDL_logf(float x)
   9.166 +{
   9.167 +#if defined(HAVE_LOGF)
   9.168 +    return logf(x);
   9.169 +#else
   9.170 +    return (float)SDL_log((double)x);
   9.171 +#endif
   9.172  }
   9.173  
   9.174  double
   9.175 @@ -177,7 +267,17 @@
   9.176      return pow(x, y);
   9.177  #else
   9.178      return SDL_uclibc_pow(x, y);
   9.179 -#endif /* HAVE_POW */
   9.180 +#endif
   9.181 +}
   9.182 +
   9.183 +float
   9.184 +SDL_powf(float x, float y)
   9.185 +{
   9.186 +#if defined(HAVE_POWF)
   9.187 +    return powf(x, y);
   9.188 +#else
   9.189 +    return (float)SDL_pow((double)x, (double)y);
   9.190 +#endif
   9.191  }
   9.192  
   9.193  double
   9.194 @@ -193,7 +293,17 @@
   9.195      return ldexp(x, n);
   9.196  #else
   9.197      return SDL_uclibc_scalbn(x, n);
   9.198 -#endif /* HAVE_SCALBN */
   9.199 +#endif
   9.200 +}
   9.201 +
   9.202 +float
   9.203 +SDL_scalbnf(float x, int n)
   9.204 +{
   9.205 +#if defined(HAVE_SCALBNF)
   9.206 +    return scalbnf(x, n);
   9.207 +#else
   9.208 +    return (float)SDL_scalbn((double)x, n);
   9.209 +#endif
   9.210  }
   9.211  
   9.212  double
   9.213 @@ -203,7 +313,7 @@
   9.214      return sin(x);
   9.215  #else
   9.216      return SDL_uclibc_sin(x);
   9.217 -#endif /* HAVE_SIN */
   9.218 +#endif
   9.219  }
   9.220  
   9.221  float 
   9.222 @@ -213,7 +323,7 @@
   9.223      return sinf(x);
   9.224  #else
   9.225      return (float)SDL_sin((double)x);
   9.226 -#endif /* HAVE_SINF */
   9.227 +#endif
   9.228  }
   9.229  
   9.230  double