Fixed bug 2245 - add SDL_acos and SDL_asin
authorSam Lantinga <slouken@libsdl.org>
Sat, 16 Nov 2013 18:56:02 -0800
changeset 8004 13da154af020
parent 8003 998458760218
child 8005 d8edfca6e3c2
Fixed bug 2245 - add SDL_acos and SDL_asin Sylvain Here's some code to add arc cosine, and arc sin functions to SDL_stdlib.c There are plainly written using SDL_atan.
include/SDL_stdinc.h
src/libm/s_atan.c
--- a/include/SDL_stdinc.h	Sat Nov 16 21:52:56 2013 -0500
+++ b/include/SDL_stdinc.h	Sat Nov 16 18:56:02 2013 -0800
@@ -340,6 +340,8 @@
 #endif
 #endif
 
+extern DECLSPEC double SDLCALL SDL_acos(double x);
+extern DECLSPEC double SDLCALL SDL_asin(double x);
 extern DECLSPEC double SDLCALL SDL_atan(double x);
 extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
 extern DECLSPEC double SDLCALL SDL_ceil(double x);
--- a/src/libm/s_atan.c	Sat Nov 16 21:52:56 2013 -0500
+++ b/src/libm/s_atan.c	Sat Nov 16 18:56:02 2013 -0800
@@ -112,3 +112,29 @@
 	}
 }
 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;
+}