Anonymous user
Trigonometric functions: Difference between revisions
m
→{{header|REXX}}: optimized a function.
m (→{{header|REXX}}: optimized a function.) |
|||
Line 3,988:
functions are wanted, you have to roll your own.
Some of the normal/regular trigonometric functions are included here.
┌──────────────────────────────────────────────────────────────────────────┐
│ One common method that ensures enough accuracy in REXX is specifying │
│ more precision (via NUMERIC DIGITS nnn) than is needed, and then │
│ displaying the number of digits that are desired, or the number(s) │
│ could be re-normalized using the FORMAT BIF. │
│ │
│ The technique used (below) is to set the numeric digits ten higher │
│ than the desired digits, as specified by the SHOWDIGS variable. │
└──────────────────────────────────────────────────────────────────────────┘
Most math (POW, EXP, LOG, LN, GAMMA, etc.), trigonometric, and hyperbolic functions need only five extra digits, but ten
<br>extra digits is safer in case the argument is close to an asymptotic point or a multiple or fractional part of pi or somesuch.
<br>precision is needed, those constants should be extended. Both '''pi''' and '''e''' could've been shown with more precision,
<br>but having large precision numbers would add to this REXX program's length. If anybody wishes to see this REXX version of
Line 4,050 ⟶ 4,051:
AcosErr: call tellErr 'Acos(x), X must be in the range of -1 ──► +1, X=' || x
/*──────────────────────────────────────────────────────────────────────────────────────*/
Atan: procedure; parse arg x; if abs(x)=1 then return pi() * .25 * sign(x)
return Asin(x / sqrt(1 + x*x) )
/*──────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x= r2r(x); a= abs(x);
numeric fuzz min(6, digits() - 3); if a=pi
if a=hpi | a=hpi*3 then return 0; if a=pi
if a=pi
/*──────────────────────────────────────────────────────────────────────────────────────*/
sin: procedure; parse arg x; x=r2r(x); numeric fuzz min(5, max(1, digits()
if x=pi*.5 then return 1; if x==pi * 1.5 then return -1
if abs(x)=pi | x=0 then return 0; return .sinCos(x,
/*──────────────────────────────────────────────────────────────────────────────────────*/
.sinCos: parse arg z 1 _,i; q= x*x
do k=2 by 2 until p=z; p= z;
return z
/*──────────────────────────────────────────────────────────────────────────────────────*/
|