Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hook up SDL_acos and SDL_asin properly.
  • Loading branch information
icculus committed Dec 9, 2013
1 parent 5e656f8 commit d01ad02
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 29 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -473,8 +473,8 @@ if(LIBC)
malloc calloc realloc free qsort abs memset memcpy memmove memcmp
strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
_ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
_stricmp _strnicmp sscanf atan atan2 ceil copysign cos cosf fabs
floor log pow scalbn sin sinf sqrt)
_stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos
cosf fabs floor log pow scalbn sin sinf sqrt)
string(TOUPPER ${_FN} _UPPER)
set(HAVE_${_UPPER} 1)
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -16628,7 +16628,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 ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt
for ac_func in atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt
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.in
Expand Up @@ -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 strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname)

AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
AC_CHECK_FUNCS(atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt)
AC_CHECK_FUNCS(atan atan2 acos asin ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt)

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_config.h.cmake
Expand Up @@ -130,6 +130,8 @@
#cmakedefine HAVE_M_PI 1
#cmakedefine HAVE_ATAN 1
#cmakedefine HAVE_ATAN2 1
#cmakedefine HAVE_ACOS 1
#cmakedefine HAVE_ASIN 1
#cmakedefine HAVE_CEIL 1
#cmakedefine HAVE_COPYSIGN 1
#cmakedefine HAVE_COS 1
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config.h.in
Expand Up @@ -133,6 +133,8 @@
#undef HAVE_M_PI
#undef HAVE_ATAN
#undef HAVE_ATAN2
#undef HAVE_ACOS
#undef HAVE_ASIN
#undef HAVE_CEIL
#undef HAVE_COPYSIGN
#undef HAVE_COS
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config_android.h
Expand Up @@ -87,6 +87,8 @@
#define HAVE_M_PI 1
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_ACOS 1
#define HAVE_ASIN 1
#define HAVE_CEIL 1
#define HAVE_COPYSIGN 1
#define HAVE_COS 1
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config_iphoneos.h
Expand Up @@ -85,6 +85,8 @@
#define HAVE_M_PI 1
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_ACOS 1
#define HAVE_ASIN 1
#define HAVE_CEIL 1
#define HAVE_COPYSIGN 1
#define HAVE_COS 1
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config_macosx.h
Expand Up @@ -104,6 +104,8 @@
#define HAVE_SYSCTLBYNAME 1
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_ACOS 1
#define HAVE_ASIN 1

/* Enable various audio drivers */
#define SDL_AUDIO_DRIVER_COREAUDIO 1
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config_psp.h
Expand Up @@ -85,6 +85,8 @@
#define HAVE_M_PI 1
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_ACOS 1
#define HAVE_ASIN 1
#define HAVE_CEIL 1
#define HAVE_COPYSIGN 1
#define HAVE_COS 1
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config_windows.h
Expand Up @@ -118,6 +118,8 @@ typedef unsigned int uintptr_t;
#define HAVE__STRNICMP 1
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_ACOS 1
#define HAVE_ASIN 1
#define HAVE_CEIL 1
#define HAVE_COS 1
#define HAVE_COSF 1
Expand Down
25 changes: 0 additions & 25 deletions src/libm/s_atan.c
Expand Up @@ -113,28 +113,3 @@ double atan(double x)
}
libm_hidden_def(atan)

double SDL_acos(double val)
{
double result;
if (val == -1.0) {
result = M_PI;
} else {
result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
if (result < 0.0)
{
result += M_PI;
}
}
return result;
}

double SDL_asin(double val)
{
double result;
if (val == -1.0) {
result = -(M_PI / 2.0);
} else {
result = (M_PI / 2.0) - SDL_acos(val);
}
return result;
}
36 changes: 36 additions & 0 deletions src/stdlib/SDL_stdlib.c
Expand Up @@ -46,6 +46,42 @@ SDL_atan2(double x, double y)
#endif /* HAVE_ATAN2 */
}

double
SDL_acos(double val)
{
#if defined(HAVE_ACOS)
return acos(val);
#else
double result;
if (val == -1.0) {
result = M_PI;
} else {
result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
if (result < 0.0)
{
result += M_PI;
}
}
return result;
#endif
}

double
SDL_asin(double val)
{
#if defined(HAVE_ASIN)
return asin(val);
#else
double result;
if (val == -1.0) {
result = -(M_PI / 2.0);
} else {
result = (M_PI / 2.0) - SDL_acos(val);
}
return result;
#endif
}

double
SDL_ceil(double x)
{
Expand Down

0 comments on commit d01ad02

Please sign in to comment.