Commit d01ad02be728fb7f934924157138c4dbc2bb1d77

Ryan C. Gordon 2013-12-09T15:17:20

Hook up SDL_acos and SDL_asin properly.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1d15fb2..7455ab8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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()
diff --git a/configure b/configure
index 0e10125..bd2c5d2 100755
--- a/configure
+++ b/configure
@@ -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"
diff --git a/configure.in b/configure.in
index 8d116a5..7c3a1b1 100644
--- a/configure.in
+++ b/configure.in
@@ -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)
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 27e5f73..08237a8 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -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
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index 574d9ae..536b297 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -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
diff --git a/include/SDL_config_android.h b/include/SDL_config_android.h
index 0826415..489b9ff 100644
--- a/include/SDL_config_android.h
+++ b/include/SDL_config_android.h
@@ -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
diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h
index ade2966..ae8a12b 100644
--- a/include/SDL_config_iphoneos.h
+++ b/include/SDL_config_iphoneos.h
@@ -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
diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h
index 9f2f76e..7825e70 100644
--- a/include/SDL_config_macosx.h
+++ b/include/SDL_config_macosx.h
@@ -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
diff --git a/include/SDL_config_psp.h b/include/SDL_config_psp.h
index 31ac2b2..989f7d8 100644
--- a/include/SDL_config_psp.h
+++ b/include/SDL_config_psp.h
@@ -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
diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h
index 6bde3f8..aa2f984 100644
--- a/include/SDL_config_windows.h
+++ b/include/SDL_config_windows.h
@@ -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
diff --git a/src/libm/s_atan.c b/src/libm/s_atan.c
index 2f24b29..970ea4d 100644
--- a/src/libm/s_atan.c
+++ b/src/libm/s_atan.c
@@ -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;
-}
diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c
index aa57d41..2cb31cb 100644
--- a/src/stdlib/SDL_stdlib.c
+++ b/src/stdlib/SDL_stdlib.c
@@ -47,6 +47,42 @@ SDL_atan2(double x, double y)
 }
 
 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)
 {
 #ifdef HAVE_CEIL