diff --git a/CMakeLists.txt b/CMakeLists.txt index 57c5b552a2..8772447aac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -783,8 +783,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 - trunc truncf) + log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf + sin sinf sqrt sqrtf tan tanf trunc truncf) string(TOUPPER ${_FN} _UPPER) set(HAVE_${_UPPER} 1) endforeach() @@ -843,8 +843,8 @@ if(LIBC) foreach(_FN 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 trunc truncf) + lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt + sqrtf tan tanf acos acosf asin asinf trunc truncf) string(TOUPPER ${_FN} _UPPER) set(_HAVEVAR "HAVE_${_UPPER}") check_symbol_exists("${_FN}" "math.h" ${_HAVEVAR}) diff --git a/configure b/configure index eb67bd8b70..21c3bbb69d 100755 --- a/configure +++ b/configure @@ -17125,7 +17125,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 trunc truncf 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 lround lroundf pow powf round roundf 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" diff --git a/configure.ac b/configure.ac index 1f262cb472..9c0bda29bc 100644 --- a/configure.ac +++ b/configure.ac @@ -348,7 +348,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 wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp 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 elf_aux_info 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 trunc truncf 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 lround lroundf pow powf round roundf 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 754b57013d..e3aae654c7 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -166,8 +166,12 @@ #cmakedefine HAVE_LOGF 1 #cmakedefine HAVE_LOG10 1 #cmakedefine HAVE_LOG10F 1 +#cmakedefine HAVE_LROUND 1 +#cmakedefine HAVE_LROUNDF 1 #cmakedefine HAVE_POW 1 #cmakedefine HAVE_POWF 1 +#cmakedefine HAVE_ROUND 1 +#cmakedefine HAVE_ROUNDF 1 #cmakedefine HAVE_SCALBN 1 #cmakedefine HAVE_SCALBNF 1 #cmakedefine HAVE_SIN 1 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 3a2a7149d3..07b94f47fe 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -170,8 +170,12 @@ #undef HAVE_LOGF #undef HAVE_LOG10 #undef HAVE_LOG10F +#undef HAVE_LROUND +#undef HAVE_LROUNDF #undef HAVE_POW #undef HAVE_POWF +#undef HAVE_ROUND +#undef HAVE_ROUNDF #undef HAVE_SCALBN #undef HAVE_SCALBNF #undef HAVE_SIN diff --git a/include/SDL_config_android.h b/include/SDL_config_android.h index d1148cf2f9..b53096bce4 100644 --- a/include/SDL_config_android.h +++ b/include/SDL_config_android.h @@ -111,8 +111,12 @@ #define HAVE_LOGF 1 #define HAVE_LOG10 1 #define HAVE_LOG10F 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 #define HAVE_POW 1 #define HAVE_POWF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE_SCALBN 1 #define HAVE_SCALBNF 1 #define HAVE_SIN 1 diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h index f06ad33540..2a8ae54262 100644 --- a/include/SDL_config_iphoneos.h +++ b/include/SDL_config_iphoneos.h @@ -112,8 +112,12 @@ #define HAVE_LOGF 1 #define HAVE_LOG10 1 #define HAVE_LOG10F 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 #define HAVE_POW 1 #define HAVE_POWF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE_SCALBN 1 #define HAVE_SCALBNF 1 #define HAVE_SIN 1 diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h index 4b45f1658b..e98e3601c8 100644 --- a/include/SDL_config_macosx.h +++ b/include/SDL_config_macosx.h @@ -115,8 +115,12 @@ #define HAVE_LOGF 1 #define HAVE_LOG10 1 #define HAVE_LOG10F 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 #define HAVE_POW 1 #define HAVE_POWF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE_SCALBN 1 #define HAVE_SCALBNF 1 #define HAVE_SIN 1 diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h index 1922217d0f..c9e9334ac5 100644 --- a/include/SDL_config_os2.h +++ b/include/SDL_config_os2.h @@ -172,8 +172,12 @@ /* #undef HAVE_LOGF */ #define HAVE_LOG10 1 /* #undef HAVE_LOG10F */ +/* #undef HAVE_LROUND */ +/* #undef HAVE_LROUNDF */ #define HAVE_POW 1 /* #undef HAVE_POWF */ +/* #undef HAVE_ROUND */ +/* #undef HAVE_ROUNDF */ #define HAVE_SIN 1 /* #undef HAVE_SINF */ /* #undef HAVE_SCALBN */ diff --git a/include/SDL_config_pandora.h b/include/SDL_config_pandora.h index 8728a63880..974922e8f3 100644 --- a/include/SDL_config_pandora.h +++ b/include/SDL_config_pandora.h @@ -95,6 +95,10 @@ #define HAVE_FLOOR 1 #define HAVE_LOG 1 #define HAVE_LOG10 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE_SCALBN 1 #define HAVE_SIN 1 #define HAVE_SINF 1 diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index 18a3638295..5190148740 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -173,6 +173,10 @@ typedef unsigned int uintptr_t; #if _MSC_VER >= 1800 #define HAVE_STRTOLL 1 #define HAVE_VSSCANF 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE_SCALBN 1 #define HAVE_SCALBNF 1 #define HAVE_TRUNC 1 diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h index 02079f53c8..2144b79faf 100644 --- a/include/SDL_config_winrt.h +++ b/include/SDL_config_winrt.h @@ -172,8 +172,12 @@ typedef unsigned int uintptr_t; #define HAVE_LOGF 1 #define HAVE_LOG10 1 #define HAVE_LOG10F 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 #define HAVE_POW 1 #define HAVE_POWF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE__SCALB 1 #define HAVE_SIN 1 #define HAVE_SINF 1 diff --git a/include/SDL_config_wiz.h b/include/SDL_config_wiz.h index f65af8eb54..3d176fb7cc 100644 --- a/include/SDL_config_wiz.h +++ b/include/SDL_config_wiz.h @@ -107,8 +107,12 @@ #define HAVE_LOGF 1 #define HAVE_LOG10 1 #define HAVE_LOG10F 1 +#define HAVE_LROUND 1 +#define HAVE_LROUNDF 1 #define HAVE_POW 1 #define HAVE_POWF 1 +#define HAVE_ROUND 1 +#define HAVE_ROUNDF 1 #define HAVE_SCALBN 1 #define HAVE_SCALBNF 1 #define HAVE_SIN 1 diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 91ccaa4515..2ada8d69ed 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -549,6 +549,10 @@ extern DECLSPEC double SDLCALL SDL_log10(double x); extern DECLSPEC float SDLCALL SDL_log10f(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_round(double x); +extern DECLSPEC float SDLCALL SDL_roundf(float x); +extern DECLSPEC long SDLCALL SDL_lround(double x); +extern DECLSPEC long SDLCALL SDL_lroundf(float x); 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); diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 8a1cc9253d..5d6eb624b6 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -788,4 +788,8 @@ #define SDL_GameControllerGetSensorData SDL_GameControllerGetSensorData_REAL #define SDL_wcscasecmp SDL_wcscasecmp_REAL #define SDL_wcsncasecmp SDL_wcsncasecmp_REAL +#define SDL_round SDL_round_REAL +#define SDL_roundf SDL_roundf_REAL +#define SDL_lround SDL_lround_REAL +#define SDL_lroundf SDL_lroundf_REAL #define SDL_SoftStretchLinear SDL_SoftStretchLinear_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index f4c2232ad6..719113b01f 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -849,4 +849,8 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerIsSensorEnabled,(SDL_GameController * SDL_DYNAPI_PROC(int,SDL_GameControllerGetSensorData,(SDL_GameController *a, SDL_SensorType b, float *c, int d),(a,b,c,d),return) SDL_DYNAPI_PROC(int,SDL_wcscasecmp,(const wchar_t *a, const wchar_t *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_wcsncasecmp,(const wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(double,SDL_round,(double a),(a),return) +SDL_DYNAPI_PROC(float,SDL_roundf,(float a),(a),return) +SDL_DYNAPI_PROC(long,SDL_lround,(double a),(a),return) +SDL_DYNAPI_PROC(long,SDL_lroundf,(float a),(a),return) SDL_DYNAPI_PROC(int,SDL_SoftStretchLinear,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 5334a512d3..5ffa28405c 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -364,6 +364,50 @@ SDL_powf(float x, float y) #endif } +double +SDL_round(double arg) +{ +#if defined HAVE_ROUND + return round(arg); +#else + if (arg >= 0.0) { + return SDL_floor(arg + 0.5); + } else { + return SDL_ceil(arg - 0.5); + } +#endif +} + +float +SDL_roundf(float arg) +{ +#if defined HAVE_ROUNDF + return roundf(arg); +#else + return (float)SDL_round((double)arg); +#endif +} + +long +SDL_lround(double arg) +{ +#if defined HAVE_LROUND + return lround(arg); +#else + return (long)SDL_round(arg); +#endif +} + +long +SDL_lroundf(float arg) +{ +#if defined HAVE_LROUNDF + return lroundf(arg); +#else + return (long)SDL_round((double)arg); +#endif +} + double SDL_scalbn(double x, int n) { diff --git a/src/video/winrt/SDL_winrtpointerinput.cpp b/src/video/winrt/SDL_winrtpointerinput.cpp index 9b36aaaad3..534bd4dfd0 100644 --- a/src/video/winrt/SDL_winrtpointerinput.cpp +++ b/src/video/winrt/SDL_winrtpointerinput.cpp @@ -116,16 +116,6 @@ WINRT_TransformCursorPosition(SDL_Window * window, return outputPosition; } -static inline int -_lround(float arg) -{ - if (arg >= 0.0f) { - return (int)floor(arg + 0.5f); - } else { - return (int)ceil(arg - 0.5f); - } -} - Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt) { @@ -389,8 +379,8 @@ WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::Mouse window, 0, 1, - _lround(mouseDeltaInSDLWindowCoords.X), - _lround(mouseDeltaInSDLWindowCoords.Y)); + SDL_lroundf(mouseDeltaInSDLWindowCoords.X), + SDL_lroundf(mouseDeltaInSDLWindowCoords.Y)); } #endif // SDL_VIDEO_DRIVER_WINRT diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 79ad2472cb..ebd0a39378 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -257,7 +257,7 @@ static int CalculateXRandRRefreshRate(const XRRModeInfo *info) { return (info->hTotal && info->vTotal) ? - round(((double)info->dotClock / (double)(info->hTotal * info->vTotal))) : 0; + SDL_round(((double)info->dotClock / (double)(info->hTotal * info->vTotal))) : 0; } static SDL_bool