Skip to content

Commit

Permalink
Fixed bug 2245 - add SDL_acos and SDL_asin
Browse files Browse the repository at this point in the history
Sylvain

Here's some code to add arc cosine, and arc sin functions to SDL_stdlib.c
There are plainly written using SDL_atan.
  • Loading branch information
slouken committed Nov 17, 2013
1 parent 923709a commit e414626
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/SDL_stdinc.h
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions src/libm/s_atan.c
Expand Up @@ -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;
}

0 comments on commit e414626

Please sign in to comment.