| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | double |
| | | SDL_atan(double x) |
| | | { |
| | | #ifdef HAVE_ATAN |
| | | #if defined(HAVE_ATAN) |
| | | 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 |
| | |
| | | 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 |
| | |
| | | #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) |
| | | { |
| | |
| | | #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) |
| | | { |
| | | #ifdef HAVE_CEIL |
| | | #if defined(HAVE_CEIL) |
| | | return ceil(x); |
| | | #else |
| | | double integer = SDL_floor(x); |
| | |
| | | #endif /* HAVE_CEIL */ |
| | | } |
| | | |
| | | float |
| | | SDL_ceilf(float x) |
| | | { |
| | | #if defined(HAVE_CEILF) |
| | | return ceilf(x); |
| | | #else |
| | | return (float)SDL_ceil((float)x); |
| | | #endif |
| | | } |
| | | |
| | | double |
| | | SDL_copysign(double x, double y) |
| | | { |
| | |
| | | return copysign(x, y); |
| | | #elif defined(HAVE__COPYSIGN) |
| | | return _copysign(x, y); |
| | | #elif defined(__WATCOMC__) && defined(__386__) |
| | | /* this is nasty as hell, but it works.. */ |
| | | unsigned int *xi = (unsigned int *) &x, |
| | | *yi = (unsigned int *) &y; |
| | | xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff); |
| | | return x; |
| | | #else |
| | | return SDL_uclibc_copysign(x, 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 |
| | |
| | | return cos(x); |
| | | #else |
| | | return SDL_uclibc_cos(x); |
| | | #endif /* HAVE_COS */ |
| | | #endif |
| | | } |
| | | |
| | | float |
| | | SDL_cosf(float x) |
| | | { |
| | | #ifdef HAVE_COSF |
| | | #if defined(HAVE_COSF) |
| | | return cosf(x); |
| | | #else |
| | | return (float)SDL_cos((double)x); |
| | |
| | | } |
| | | |
| | | double |
| | | SDL_exp(double x) |
| | | { |
| | | #if defined(HAVE_EXP) |
| | | return exp(x); |
| | | #else |
| | | return SDL_uclibc_exp(x); |
| | | #endif |
| | | } |
| | | |
| | | float |
| | | SDL_expf(float x) |
| | | { |
| | | #if defined(HAVE_EXPF) |
| | | return expf(x); |
| | | #else |
| | | return (float)SDL_exp((double)x); |
| | | #endif |
| | | } |
| | | |
| | | double |
| | | SDL_fabs(double x) |
| | | { |
| | | #if defined(HAVE_FABS) |
| | | return fabs(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 |
| | |
| | | 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 |
| | | SDL_fmod(double x, double y) |
| | | { |
| | | #if defined(HAVE_FMOD) |
| | | return fmod(x, y); |
| | | #else |
| | | return SDL_uclibc_fmod(x, y); |
| | | #endif |
| | | } |
| | | |
| | | float |
| | | SDL_fmodf(float x, float y) |
| | | { |
| | | #if defined(HAVE_FMODF) |
| | | return fmodf(x, y); |
| | | #else |
| | | return (float)SDL_fmod((double)x, (double)y); |
| | | #endif |
| | | } |
| | | |
| | | double |
| | |
| | | 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 |
| | | SDL_log10(double x) |
| | | { |
| | | #if defined(HAVE_LOG10) |
| | | return log10(x); |
| | | #else |
| | | return SDL_uclibc_log10(x); |
| | | #endif |
| | | } |
| | | |
| | | float |
| | | SDL_log10f(float x) |
| | | { |
| | | #if defined(HAVE_LOG10F) |
| | | return log10f(x); |
| | | #else |
| | | return (float)SDL_log10((double)x); |
| | | #endif |
| | | } |
| | | |
| | | double |
| | |
| | | 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 |
| | |
| | | return scalbn(x, n); |
| | | #elif defined(HAVE__SCALB) |
| | | return _scalb(x, n); |
| | | #elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2) |
| | | /* from scalbn(3): If FLT_RADIX equals 2 (which is |
| | | * usual), then scalbn() is equivalent to ldexp(3). */ |
| | | 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 |
| | |
| | | return sin(x); |
| | | #else |
| | | return SDL_uclibc_sin(x); |
| | | #endif /* HAVE_SIN */ |
| | | #endif |
| | | } |
| | | |
| | | float |
| | | SDL_sinf(float x) |
| | | { |
| | | #ifdef HAVE_SINF |
| | | #if defined(HAVE_SINF) |
| | | return sinf(x); |
| | | #else |
| | | return (float)SDL_sin((double)x); |
| | | #endif /* HAVE_SINF */ |
| | | #endif |
| | | } |
| | | |
| | | double |
| | |
| | | |
| | | int SDL_abs(int x) |
| | | { |
| | | #ifdef HAVE_ABS |
| | | #if defined(HAVE_ABS) |
| | | return abs(x); |
| | | #else |
| | | return ((x) < 0 ? -(x) : (x)); |
| | | #endif |
| | | } |
| | | |
| | | #ifdef HAVE_CTYPE_H |
| | | #if defined(HAVE_CTYPE_H) |
| | | int SDL_isdigit(int x) { return isdigit(x); } |
| | | int SDL_isspace(int x) { return isspace(x); } |
| | | int SDL_isupper(int x) { return isupper(x); } |
| | | int SDL_islower(int x) { return islower(x); } |
| | | int SDL_toupper(int x) { return toupper(x); } |
| | | int SDL_tolower(int x) { return tolower(x); } |
| | | #else |
| | | int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); } |
| | | int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); } |
| | | int SDL_isupper(int x) { return ((x) >= 'A') && ((x) <= 'Z'); } |
| | | int SDL_islower(int x) { return ((x) >= 'a') && ((x) <= 'z'); } |
| | | int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); } |
| | | int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); } |
| | | #endif |
| | |
| | | __declspec(selectany) int _fltused = 1; |
| | | #endif |
| | | |
| | | /* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */ |
| | | #if _MSC_VER >= 1600 && defined(_WIN64) && !defined(_DEBUG) |
| | | /* The optimizer on Visual Studio 2005 and later generates memcpy() calls */ |
| | | #if (_MSC_VER >= 1400) && defined(_WIN64) && !defined(_DEBUG) && !(_MSC_VER >= 1900 && defined(_MT)) |
| | | #include <intrin.h> |
| | | |
| | | #pragma function(memcpy) |
| | |
| | | _ftol(); |
| | | } |
| | | |
| | | /* 64-bit math operators for 32-bit systems */
|
| | | void
|
| | | __declspec(naked)
|
| | | _allmul()
|
| | | {
|
| | | /* *INDENT-OFF* */
|
| | | __asm {
|
| | | mov eax, dword ptr[esp+8]
|
| | | mov ecx, dword ptr[esp+10h]
|
| | | or ecx, eax
|
| | | mov ecx, dword ptr[esp+0Ch]
|
| | | jne hard
|
| | | mov eax, dword ptr[esp+4]
|
| | | mul ecx
|
| | | ret 10h
|
| | | hard:
|
| | | push ebx
|
| | | mul ecx
|
| | | mov ebx, eax
|
| | | mov eax, dword ptr[esp+8]
|
| | | mul dword ptr[esp+14h]
|
| | | add ebx, eax
|
| | | mov eax, dword ptr[esp+8]
|
| | | mul ecx
|
| | | add edx, ebx
|
| | | pop ebx
|
| | | ret 10h
|
| | | }
|
| | | /* *INDENT-ON* */
|
| | | /* 64-bit math operators for 32-bit systems */ |
| | | void |
| | | __declspec(naked) |
| | | _allmul() |
| | | { |
| | | /* *INDENT-OFF* */ |
| | | __asm { |
| | | mov eax, dword ptr[esp+8] |
| | | mov ecx, dword ptr[esp+10h] |
| | | or ecx, eax |
| | | mov ecx, dword ptr[esp+0Ch] |
| | | jne hard |
| | | mov eax, dword ptr[esp+4] |
| | | mul ecx |
| | | ret 10h |
| | | hard: |
| | | push ebx |
| | | mul ecx |
| | | mov ebx, eax |
| | | mov eax, dword ptr[esp+8] |
| | | mul dword ptr[esp+14h] |
| | | add ebx, eax |
| | | mov eax, dword ptr[esp+8] |
| | | mul ecx |
| | | add edx, ebx |
| | | pop ebx |
| | | ret 10h |
| | | } |
| | | /* *INDENT-ON* */ |
| | | } |
| | | |
| | | void |
| | |
| | | { |
| | | /* *INDENT-OFF* */ |
| | | __asm { |
| | | cmp cl,40h |
| | | jae RETZERO |
| | | cmp cl,3Fh |
| | | jae RETSIGN |
| | | cmp cl,20h |
| | | jae MORE32 |
| | | shrd eax,edx,cl |
| | |
| | | ret |
| | | MORE32: |
| | | mov eax,edx |
| | | xor edx,edx |
| | | sar edx,1Fh |
| | | and cl,1Fh |
| | | sar eax,cl |
| | | ret |
| | | RETZERO: |
| | | xor eax,eax |
| | | xor edx,edx |
| | | RETSIGN: |
| | | sar edx,1Fh |
| | | mov eax,edx |
| | | ret |
| | | } |
| | | /* *INDENT-ON* */ |