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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
index f0780a2..9a421ba 100644
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -340,6 +340,8 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char
#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);
diff --git a/src/libm/s_atan.c b/src/libm/s_atan.c
index f664f0e..2f24b29 100644
--- a/src/libm/s_atan.c
+++ b/src/libm/s_atan.c
@@ -112,3 +112,29 @@ 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;
+}