home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hacker Chronicles 2
/
HACKER2.BIN
/
150.MATHLIB0.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-05-25
|
2KB
|
66 lines
UNIT MathLib0;
INTERFACE
USES Extended_Reals;
FUNCTION log (x:REAL) : REAL;
FUNCTION exp10 (x:REAL) : REAL;
FUNCTION sinc (x:REAL) : REAL;
(****************************************************************************)
IMPLEMENTATION
CONST
ln10 = 2.302585092994046;
FUNCTION log (x:REAL) : REAL;
BEGIN
log:=ln(x)/ln10;
END;
FUNCTION exp10 (x:REAL) : REAL;
BEGIN
exp10:=exp(x*ln10);
END;
FUNCTION sinc (x:REAL) : REAL;
{ The accuracy of sin(x)/x for small x was tested up to MaxInt to be }
{ within 1e-6 of the value computed from the Taylor series expansion. }
CONST
s : ARRAY [1..6] OF REAL
= (+1.00000000000000, { +1/1! }
-0.16666666666667, { -1/3! }
+8.33333333333333e-3, { +1/5! }
-1.98412698412698e-4, { -1/7! }
+2.75573192239859e-6, { +1/9! }
-2.50521083854417e-8); { -1/11! }
VAR
xx : REAL; { xx = x^2 }
temp : REAL;
BEGIN {sinc}
IF (abs(x) < (PI/MaxInt))
THEN BEGIN
{Calculate sinc(x) from Taylor Series}
{to avoid arithmetic overflow}
xx:=x*x;
temp:=xx*(s[4]+xx*(s[5]+xx*s[6]));
sinc:=s[1]+xx*(s[2]+xx*(s[3]+temp));
END {THEN}
ELSE
sinc:=sin(x)/x;
END; {sinc}
(****************************************************************************)
BEGIN {Initialization}
END. {MathLib0}