For an assignment I have to write a procedure to calculate the sine of a number (located in EAX). I'm suppose to use a taylor expansion to approximate the sin(eax). I have most of the code working. If I have a number in EAX, I can calculate the 7th order Taylor expansion of the number. I have a macro called mTaylor_Order integer. The macro will calculate ST(0)^integer / integer!. The Taylor approximation works fine. However, a 7th order Taylor approximation of Sin x is only accurate between -pi and -pi. I have to be able to calculate the sine of any number. The way I tried to shift any number (I will call it Y) into a number between -pi and pi (call it X) is that I use the following equation:
X = pi * (modulo(Y/pi)).
The program does not work though. Any ideas on how I should shift Y so it will be a number between -pi and pi?
Sine PROC
fldpi
fld Z
fprem
fldpi
fmul
fstp X
finit
fld X
mTaylor_Order 1
fld X
mTaylor_Order 5
fadd
fld X
mTaylor_Order 3
fsub
fld X
mTaylor_Order 7
fsub
fstp X
mov eax, X
call WriteHex
call Crlf
ret
Sine ENDP
X = pi * (modulo(Y/pi)).
The program does not work though. Any ideas on how I should shift Y so it will be a number between -pi and pi?
Sine PROC
fldpi
fld Z
fprem
fldpi
fmul
fstp X
finit
fld X
mTaylor_Order 1
fld X
mTaylor_Order 5
fadd
fld X
mTaylor_Order 3
fsub
fld X
mTaylor_Order 7
fsub
fstp X
mov eax, X
call WriteHex
call Crlf
ret
Sine ENDP