home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
elan
/
demo
/
sine.eln
< prev
next >
Wrap
Text File
|
1987-09-02
|
1KB
|
68 lines
REAL PROC sine (REAL CONST arg):
REAL CONST twopi :: 2.0 * pi;
REAL VAR x :: arg;
REAL VAR term :: x, sum :: 0.0, xsquared :: x * x;
INT VAR n :: 1;
reduce domain;
REP
REAL CONST old :: sum;
take next term
UNTIL sum = old
ENDREP;
sum.
reduce domain:
IF x > pi
THEN
REP x DECR twopi
UNTIL x <= pi
ENDREP
ELIF x < - pi
THEN
REP x INCR twopi
UNTIL x >= - pi
ENDREP
FI.
take next term:
sum INCR term;
n INCR 1;
term := - term * xsquared / real ((2 * n - 1) * (2 * n - 2)).
ENDPROC sine;
program:
put (" built in programmed difference");
line (2);
INT VAR i;
FOR i FROM 1 UPTO 15
REP
REAL CONST x :: pi * real (i) / 18.0;
put (sin (x));
put (sine (x));
put (sin (x) - sine (x));
line
ENDREP.
speedtest:
REAL VAR x;
INT VAR mx;
put ("How many times? ");
get (mx);
line;
INT CONST dummy :: exectime;
UPTO mx
REP
x := sin (1.2);
put ("+")
ENDREP;
put (exectime);
line;
UPTO mx
REP
x := sine (1.2);
put ("-")
ENDREP;
put (exectime).