;Trigonometric and other general Math functions, ;Written by Eóin O'Callaghan. ; ;Acknowledgments to the author of this site, http://www.rism.com/Trig/Trig02.htm ;and to bitRAKE for a nice optimisation of the fscale function. ; ;Sign Function sgn(st) = x -> 1 « st > 0, 0 « st = 0, -1 « st < 0 ;2 to power st pow2(st) = 2^st ;st to power st1 pow(st,st1) = 2^(st*log2st1) ;Logarithm st to base st1 log(st,st1) = log(st)/log(st1) ;Exponent exp(st) = 2^(st*log2e) ;Natural Log ln(st) = (Log2e)*(log2st) ; ;Secant sec(st) = 1 / cos(st) ;Cosecant csc(st) = 1 / sin(st) ;Cotangent cot(st) = 1 / tan(st) ; ;Inverse Sine asin(st) = atan(st / sqrt((1 - st)(1 + st))) ;Inverse Cosine acos(st) = atan(sqrt((1 - st)(1 + st)) / st) ;Inverse Secant asec(st) = atan(sqrt((st - 1)(st + 1))) ;Inverse Cosecant acsc(st) = Atn(1 / sqrt((st - 1)(st + 1))) ;Inverse Cotangent acot(st) = Atn(1 / st) ; ;Hyperbolic Sine sinh(st) = (exp(st) - exp(-st)) / 2 ;Hyperbolic Cosine cosh(st) = (exp(st) + exp(-st)) / 2 ;Hyperbolic Tangent tanh(st) = (exp(st) - exp(-st)) / (exp(st) + exp(-st)) ;Hyperbolic Secant sech(st) = 2 / (exp(st) + exp(-st)) ;Hyperbolic Cosecant csch(st) = 2 / (exp(st) - exp(-st)) ;Hyperbolic Cotangent coth(st) = (exp(st) + exp(-st)) / (exp(st) - exp(-st)) ; ;Inverse Hyperbolic Sine asinh(st) = ln(st + Sqr(st * st + 1)) ;Inverse Hyperbolic Cosine acosh(st) = ln(st + Sqr(st * st - 1)) ;Inverse Hyperbolic Tangent atanh(st) = ln((1 + st) / (1 - st)) / 2 ;Inverse Hyperbolic Secant asech(st) = ln((Sqr(-st * st + 1) + 1) / st) ;Inverse Hyperbolic Cosecant acsch(st) = ln((1 + sqrt(1 + st*st)) / st) ;Inverse Hyperbolic Cotangent acoth(st) = ln((st + 1) / (st - 1)) / 2 FASTEXP = 1 .data iL2e dt 3FFEB17217F7D1CF79ACh PlusHalf dd 0.5 PlusOne dd 1.0 MinusOne dd -1.0 PlusTwo dd 2.0 fSgn MACRO ;Sgn(st(0)) ; st > 0 -> st = 1 sub esp,4 ; st = 0 -> st = 0 fldz ; st < 0 -> st = -1 xor eax,eax ; 9 clocks fcomip st,st(1) cmova eax,MinusOne cmovb eax,PlusOne fstp st mov [esp],eax fld pd[esp] add esp,4 EndM IF FASTEXP fPow2 MACRO ; 2^st, 98 clocks sub esp,16 fist dword ptr [esp+12] fld1 fstp tbyte ptr [esp] fisub dword ptr [esp+12] mov eax,[esp+12] add [esp+8],eax f2xm1 fld1 fadd fld tbyte ptr [esp] fmul add esp,16 EndM ELSE fPow2 MACRO ; 2^st fld st frndint fsub st(1),st fld1 fscale fxch fstp st fxch f2xm1 fld1 fadd fmul EndM ENDIF fExp MACRO ; e^st, 99 clocks fldl2e fmul fPow2 EndM fPow MACRO ; st^st(1), 200 clocks fyl2x fPow2 EndM log Macro ; Log st to base st(1), 209 clocks fld1 fxch fyl2x fxch fld1 fxch fyl2x fdiv EndM fLn MACRO ;Log st to base e, 104 clocks fld iL2e fxch fyl2x EndM fTan Macro ;Tan(st), 136-148 clocks fptan fstp st EndM fSec MACRO ;Sec(st), 124 clocks fcos fdivr PlusOne EndM fCsc MACRO ;Cosec(st), 124 clocks fsin fdivr PlusOne EndM fCot Macro ;Sec(st), 167-177 clocks fptan fstp st fdivr PlusOne EndM fAsin Macro ;ArcSin(st), 66 clocks fld st fmul st,st fsubr PlusOne fsqrt fpatan EndM fAcos MACRO ;ArcCos(st), 66 clocks fld st fmul st,st fsubr PlusOne fsqrt fxch fpatan EndM fAtan MACRO ;ArcTan(st), 144 clocks fld1 fpatan EndM fAsec Macro ;ArcSec(st), 230 clocks fmul st,st fsub PlusOne fsqrt fld1 fpatan EndM fAcsc Macro ;ArcsoCec(st), 347 clocks fmul st,st fsub PlusOne fsqrt fdivr PlusOne fld1 fpatan EndM fAcot Macro ;ArcCotan(st), 174 clocks fdivr PlusOne fld1 fpatan EndM fSinh Macro ;Hyperbolic Sin(st), 148 clocks fExp fld st fdivr PlusOne fsub fmul PlusHalf EndM fCosh Macro ;Hyperbolic Cos(st), 147 clocks fExp fld st fdivr PlusOne fadd fmul PlusHalf EndM fTanh Macro ;Hyperbolic Tan(st), 140-141 clocks fExp fmul st,st fld st fadd PlusOne fxch fsub PlusOne fdivr EndM fSech Macro ;Hyperbolic Sec(st), 166 clocks fExp fld st fdivr PlusOne fadd fdivr PlusTwo EndM fCsch Macro ;Hyperbolic Cosec(st), 166 clocks fExp fld st fdivr PlusOne fsub fdivr PlusTwo EndM fCoth Macro ;Hyperbolic Cotan(st), 140-141 clocks fExp fmul st,st fld st fadd PlusOne fxch fsub PlusOne fdiv EndM fAsinh Macro ;Arc Hyperbolic Sin(st), 169 clocks fld st fmul st,st fadd PlusOne fsqrt fadd fLn EndM fAcosh Macro ;Arc Hyperbolic Cos(st), 169 clocks fld st fmul st,st fsub PlusOne fsqrt fadd fLn EndM fAtanh Macro ;Arc Hyperbolic Tan(st), 156-171 clocks fadd PlusOne fld st fsubr PlusTwo fdiv fLn fmul PlusHalf EndM fAsech Macro ;Arc Hyperbolic Sec(st), 201 clocks fld st fmul st,st fsubr PlusOne fsqrt fadd PlusOne fdivr fLn EndM fAcsch Macro ;Arc Hyperbolic Cosec(st), 213 clocks fld st fmul st,st fadd PlusOne fsqrt fadd PlusOne fdivr fLn EndM fAcoth Macro ;Arc Hyperbolic Cotan(st), 156-171 clocks fadd PlusOne fld st fsub PlusTwo fdiv fLn fmul PlusHalf EndM