; math_asin.asm
;
; Assembly language source for the arc sine 
; function:


            include math.inc
            include aoalib.inc
            
; ASIN(x)-  Computes the arcsine of st(0) and leaves  
;           the result in st(0).
;           Allowable range: -1<=x<=+1                                   
;           There must be at least two free registers 
;           for this function to operate properly.                                         
;                                                                       
; asin(x) = Atan(x / Sqrt(-x * x + 1))
; 
                                      

            .code
math_asin   proc
            fld     st(0)   ; Duplicate X on tos.
            fld     st(0)   ; Duplicate X on tos.
            fmulp           ; X**2.
            fld1            ; 1-X**2.
            fsubrp          ; 
            
            fldz            ; Make sure we're not
            fcomip  st(0), st(1) ;trying to compute
            ja      badSqrt ; sqrt(negative number).
            
            fsqrt           ; sqrt(1-X**2).

            fpatan          ; atan(x/sqrt(-x*x+1))
            ret
            
badSqrt:    fstp    st(0)    ;pop ST(0)
            fld     math_inf ;Return infinity
            ret

math_asin   endp
            end