LF: sine calculus
[Prev][Next][Index][Thread]
LF: sine calculus
I am sorry: last message about "prog stuff" and my sine lib was a little
confused... I hadn' t thought about my comments being in french...
So: to make myself clear: i wish to calculate a sine using : sine(x)=x -
x^3/3! + x^5/5! - ...
here is the pseudo code i wrote to do this:
Table Descriptor:
D0: entry parameters to the program
D1: answer of the program
D2: number of digits in the entry and the answer
D3: exit of the "calc" subroutine: intermediate terms
D4: temporary counter
D6: Counter : power of the calculated term
D7: Counter : number of the calculated term
Pseudo code:
* initialisation of all data regs:
ex: #1500->D0 ( sine(1.500)
1->D6,D7,A5
#1000->D2 ( 4 numbers: 10^(4-1) )
0->all others
* start:
* 1st term: D0->D1 ( sin(x) = x+... )
* iter_1:
* increase D6,D7 : D6+2->D6 and D7+1->D7
* branch to "calc" ( in param D6 ( power of the term to calculate )
out param D3 ( term calculated ) )
* test if D7 is odd or even ( in fact test on the sign of the term
added to D1 )
* odd: substract D3 to D1
* even: add D3 to D1
* test if D3=0 ( test on precision )
* yes: exit
* no: branch to iter_1
* end
* calc: ( in param : D6 . exit: D3 )
* initialise intermediate counter: D6->D4
* D0->D3 ( 1st term of the power )
* iter_2:
* decrease D4
* D3*D0->D3 multipling to calc the power
* D3/D2->D3 dividing because all numbers are multiplied by 1000.
So dividing by 1000.
* branch to iter_2 while D4 <> 1
* init D4: D6->D4
* iter_3:
* D3/D4->D3 ( dividing by all naturals between D6 and 1: D3/D6!->D3 )
* dec D4
* branch to iter_3 while D4 <> 1
* end_calc
and here is the prog i wrote to do this:
prog_code:
jsr reclib[init]
clr.l D0
clr.l D1
clr.l D2
clr.l D3
clr.l D4
clr.l D5
clr.l D6
clr.l D7
move.w #1500,D0
move.w #1,D6
move.w #1,D7
move.w D0,D1
move.w #1000,D2
move.w #0,A4
move.w #1,A5
iterer1:
add.w #1,D7
Add.w #2,D6
bsr calc
btst #0,D7
bne diff
add.w D3,D1
retour:
cmp A5,D3
bge fin
bra iterer1
rts
calc:
move.w #0,D4
move.w D0,D3
move.w D6,D4
\iterer2
sub.w #1,D4
mulu.l D0,D3
divu.l D2,D3
cmp D4,A4
bne \iterer2
move.w D6,D4
\iterer3
divu.l D4,D3
sub.w #1,D4
cmp D4,A4
bne \iterer3
diff:
sub.w D3,D1
bra retour
fin:
move.l D1,D0
move.l #0,D1
move.l #3,D2
move.l #7,D4
jsr hexlib[put_hex]
jsr flib[idle_loop]
rts
For those who got that far, the prog i wrote doesn' t work: it writes 2 diff
hex numbers on the screen ( it should write only one ) and none of these is
the awaited answer.... So if someone has ideas... I would be gratefull for
all help...
Something else: i have been looking at torus code: jimmy used a bin file
containing sine table... someone know if he established this file by hand or
if he wrote a prog building it ?
Mathiue, <hm lacage@aol.com>