We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2245

Summary: add SDL_acos and SDL_asin
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.1   
Hardware: All   
OS: All   
Attachments: src for SDL_acos and SDL_asin
new version asin acos + test case

Description Sylvain 2013-11-16 14:35:28 UTC
Created attachment 1448 [details]
src for SDL_acos and SDL_asin

Here's some code to add arc cosine, and arc sin functions to SDL_stdlib.c
There are plainly written using SDL_atan.
Comment 1 Sam Lantinga 2013-11-16 19:49:32 UTC
Looks pretty good...
When is this condition true? if (val > 1e-6 && val < -1e-6)
Comment 2 Sylvain 2013-11-16 20:20:45 UTC
Actually never, this is a mistake. I wanted to write:

if (val > -1e^-6 && val  < 1e^-6)

to avoid the division by 0. 

but this has been catched anyway by SDL_atan, because it gave me the correct results with my test cases.

(but I dont know if this would have been also catched by the ulibc version ?)
Comment 3 Sam Lantinga 2013-11-16 20:42:05 UTC
sin() asin() mismatch at -PI/2:
Unexpected result: y = -1.570796, x = -1.000000, result = 1.570796
Comment 4 Sylvain 2013-11-16 21:14:34 UTC
Created attachment 1449 [details]
new version asin acos + test case

new version of asin/acos + test case printf
Comment 5 Sylvain 2013-11-16 21:15:42 UTC
yes a modulo 2 PI problem.
I also check the "-inf and +inf"
and also the "+0 and -O"
Comment 6 Sam Lantinga 2013-11-17 03:00:07 UTC
Okay, I treat 0 and -0 as equivalent, and I never got -nan result in my testing, so here's the code I checked in:
https://hg.libsdl.org/SDL/rev/13da154af020

Thanks!
Comment 7 Sylvain 2013-11-17 08:49:52 UTC
ok thanks great !

This is not a problem for me, but for information I now get the difference on -NaN and -O.

here's some log I got on linux :

case -2.000000.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case -1.685841.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case -1.371681.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case -1.057522.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case -0.743363.     asin=-0.838084 SDL_asin=-0.838084         acos=2.408880 SDL_acos=2.408880
case -0.429204.     asin=-0.443611 SDL_asin=-0.443611         acos=2.014407 SDL_acos=2.014407
case -0.115044.     asin=-0.115300 SDL_asin=-0.115300         acos=1.686096 SDL_acos=1.686096
case 0.199115.     asin=0.200455 SDL_asin=0.200455         acos=1.370342 SDL_acos=1.370342
case 0.513274.     asin=0.538995 SDL_asin=0.538995         acos=1.031801 SDL_acos=1.031801
case 0.827433.     asin=0.974522 SDL_asin=0.974522         acos=0.596275 SDL_acos=0.596275
case 1.141593.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case 1.455752.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case 1.769911.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan

case inf.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan
case -inf.     asin=nan SDL_asin=-nan         acos=nan SDL_acos=-nan

case 0.000000.     asin=0.000000 SDL_asin=0.000000         acos=1.570796 SDL_acos=1.570796
case -0.000000.     asin=-0.000000 SDL_asin=0.000000         acos=1.570796 SDL_acos=1.570796

case 1.000000.     asin=1.570796 SDL_asin=1.570796         acos=0.000000 SDL_acos=0.000000
case -1.000000.     asin=-1.570796 SDL_asin=-1.570796         acos=3.141593 SDL_acos=3.141593
Comment 8 Sylvain 2013-11-17 09:07:11 UTC
Also, it seems to compile correctly on linux, but on android it bring an undefined reference !
Comment 9 Sam Lantinga 2013-11-17 20:45:07 UTC
I just built on Android with no problems. What are you seeing?
Comment 10 Sylvain 2013-11-17 20:54:11 UTC
I see a link error when building androind while using the function !

"libm" seems not to be in the Android.mk file