Fixed bug 2245 - add SDL_acos and SDL_asin
authorSam Lantinga <slouken@libsdl.org>
Sat, 16 Nov 2013 18:56:02 -0800
changeset 800413da154af020
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
     1.1 --- a/include/SDL_stdinc.h	Sat Nov 16 21:52:56 2013 -0500
     1.2 +++ b/include/SDL_stdinc.h	Sat Nov 16 18:56:02 2013 -0800
     1.3 @@ -340,6 +340,8 @@
     1.4  #endif
     1.5  #endif
     1.6  
     1.7 +extern DECLSPEC double SDLCALL SDL_acos(double x);
     1.8 +extern DECLSPEC double SDLCALL SDL_asin(double x);
     1.9  extern DECLSPEC double SDLCALL SDL_atan(double x);
    1.10  extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
    1.11  extern DECLSPEC double SDLCALL SDL_ceil(double x);
     2.1 --- a/src/libm/s_atan.c	Sat Nov 16 21:52:56 2013 -0500
     2.2 +++ b/src/libm/s_atan.c	Sat Nov 16 18:56:02 2013 -0800
     2.3 @@ -112,3 +112,29 @@
     2.4  	}
     2.5  }
     2.6  libm_hidden_def(atan)
     2.7 +
     2.8 +double SDL_acos(double val)
     2.9 +{
    2.10 +    double result;
    2.11 +    if (val == -1.0) {
    2.12 +        result = M_PI;
    2.13 +    } else {
    2.14 +        result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
    2.15 +        if (result < 0.0)
    2.16 +        {
    2.17 +            result += M_PI;
    2.18 +        }
    2.19 +    }
    2.20 +    return result;
    2.21 +}
    2.22 +
    2.23 +double SDL_asin(double val)
    2.24 +{
    2.25 +    double result;
    2.26 +    if (val == -1.0) {
    2.27 +        result = -(M_PI / 2.0);
    2.28 +    } else {
    2.29 +        result = (M_PI / 2.0) - SDL_acos(val);
    2.30 +    }
    2.31 +    return result;
    2.32 +}