asin.go 340 B

123456789101112131415161718192021222324252627
  1. package math32
  2. func Asin(x float32) float32 {
  3. if x == 0 {
  4. return x // special case
  5. }
  6. sign := false
  7. if x < 0 {
  8. x = -x
  9. sign = true
  10. }
  11. if x > 1 {
  12. return NaN() // special case
  13. }
  14. temp := Sqrt(1 - x*x)
  15. if x > 0.7 {
  16. temp = Pi/2 - satan(temp/x)
  17. } else {
  18. temp = satan(x / temp)
  19. }
  20. if sign {
  21. temp = -temp
  22. }
  23. return temp
  24. }