Assembly Trig from http://masm32.com/board/index.php?topic=4118.0
.data ;; for both trig routines
piover2 real8 1.5707963267948966
twooverpi real8 0.63661977236758138
.code
; »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
.data ; data used by trigC MACRO
__cos1 real8 -1.2337005501361697 ; 1/2 (pi/2)^2
__cos2 real8 0.16666666666666667 ; 2/(3*4)
__cos3 real8 0.06666666666666667 ; 2/(5*6)
__cos4 real8 0.03571428571428571 ; 2/(7*8)
one real8 1.0
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;;******************************* ;; sin or cos in st(0), uses 4 regs
trigC MACRO sincosflag:=<0> ;; but needs one extra per term
;;*******************************
fmul twooverpi ;; div by pi/2 to put in 4 quadrants
fld st
fisttp qword ptr [esp-8] ;; math "int" truncate, down towards -inf
mov eax, dword ptr [esp-8] ;; (lower word of) int quotient x / pi/2
fild qword ptr [esp-8]
add eax, sincosflag ;; sin if sincosflag = 0, cos if 1
fsub ;; now mod 1 (0 to .999999) meaning 0-pi/2
test eax, 1
jnz @F
fld1
fsubrp ;; replace w/ 1-x for these quadrants
@@:
fmul st, st
fmul __cos1
fld st ;; c1*x^2, c1*x^2
fmul st, st(1) ;; c1^2*x^4, c1*x^2
fmul __cos2 ;; c2*c1^2*x^4, c1*x^2
fld st ;; c2*c1^2*x^4, c2*c1^2*x^4, c1*x^2
fmul st, st(2) ;; c2*c1^3*x^6, c2*c1^2*x^4, c1*x^2
fmul __cos3 ;; c3*c2*c1^3*x^6, c2*c1^2*x^4, c1*x^2
IF MORE_PRECISION EQ 1 ;; do one more term
fld st ;; c3*c2*c1^3*x^6, c3*c2*c1^3*x^6, c2*c1^2*x^4, c1*x^2
fmul st, st(3) ;; c3*c2*c1^4*x^8, c3*c2*c1^3*x^6, c2*c1^2*x^4, c1*x^2
fmul __cos4 ;; c4*c3*c2*c1^4*x^8, c3*c2*c1^3*x^6, c2*c1^2*x^4, c1*x^2
fadd
ENDIF
fadd
fadd
fadd one ;; answer in st(0) all other regs free
and eax, 2
je @F
fchs ;; was in a negative quadrant
@@:
ENDM
;;*******************************