Skip to content

Commit

Permalink
stdlib: Add SDL_trunc and SDL_truncf
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 10, 2020
1 parent a791689 commit d292f6b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Expand Up @@ -767,7 +767,8 @@ if(LIBC)
_stricmp _strnicmp strtok_s sscanf
acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf
log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)
log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf
trunc truncf)
string(TOUPPER ${_FN} _UPPER)
set(HAVE_${_UPPER} 1)
endforeach()
Expand Down Expand Up @@ -817,7 +818,7 @@ if(LIBC)
atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf
exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f
pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf acos acosf
asin asinf)
asin asinf trunc truncf)
string(TOUPPER ${_FN} _UPPER)
set(_HAVEVAR "HAVE_${_UPPER}")
check_function_exists("${_FN}" ${_HAVEVAR})
Expand Down
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -17132,7 +17132,7 @@ if test "x$ac_cv_lib_m_pow" = xyes; then :
LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"
fi

for ac_func in acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf
for ac_func in acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f 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"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -339,7 +339,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 wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r 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 _Exit)

AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)
AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f 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)
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_stdinc.h
Expand Up @@ -529,6 +529,8 @@ 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_trunc(double x);
extern DECLSPEC float SDLCALL SDL_truncf(float x);
extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
extern DECLSPEC double SDLCALL SDL_log(double x);
Expand Down
2 changes: 2 additions & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -761,3 +761,5 @@
#define SDL_UnlockSensors SDL_UnlockSensors_REAL
#define SDL_Metal_GetLayer SDL_Metal_GetLayer_REAL
#define SDL_Metal_GetDrawableSize SDL_Metal_GetDrawableSize_REAL
#define SDL_trunc SDL_trunc_REAL
#define SDL_truncf SDL_truncf_REAL
2 changes: 2 additions & 0 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -820,3 +820,5 @@ SDL_DYNAPI_PROC(void,SDL_LockSensors,(void),(),)
SDL_DYNAPI_PROC(void,SDL_UnlockSensors,(void),(),)
SDL_DYNAPI_PROC(void*,SDL_Metal_GetLayer,(SDL_MetalView a),(a),return)
SDL_DYNAPI_PROC(void,SDL_Metal_GetDrawableSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
SDL_DYNAPI_PROC(double,SDL_trunc,(double a),(a),return)
SDL_DYNAPI_PROC(float,SDL_truncf,(float a),(a),return)
21 changes: 21 additions & 0 deletions src/stdlib/SDL_stdlib.c
Expand Up @@ -260,6 +260,27 @@ SDL_floorf(float x)
#endif
}

double
SDL_trunc(double x)
{
#if defined(HAVE_TRUNC)
return trunc(x);
#else
/* !!! FIXME: there are more formal (correct!) ways to do this. */
return (double) ((Sint64) x);
#endif
}

float
SDL_truncf(float x)
{
#if defined(HAVE_TRUNCF)
return truncf(x);
#else
return (float)SDL_trunc((double)x);
#endif
}

double
SDL_fmod(double x, double y)
{
Expand Down

0 comments on commit d292f6b

Please sign in to comment.