Anonymous user
Trigonometric functions: Difference between revisions
m
→{{header|REXX}}: optimized the COS and SIN functions, changed wording in the REXX section header.
No edit summary |
m (→{{header|REXX}}: optimized the COS and SIN functions, changed wording in the REXX section header.) |
||
Line 4,152:
=={{header|REXX}}==
The REXX language doesn't have any trig functions (or for that matter, a square root [SQRT] function), so if higher math
<br>functions are wanted, you'll 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 │
▲Some of the normal/regular trigonometric functions are included here.
│ more precision (via NUMERIC DIGITS nnn) than is needed, and then │
▲ ┌──────────────────────────────────────────────────────────────────────────┐
│
│
│
└──────────────────────────────────────────────────────────────────────────┘▼
▲ └──────────────────────────────────────────────────────────────────────────┘
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.
It should also be noted that both the '''pi''' and '''e''' constants have only around 77 decimal digits as included here, if more
<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
<br>of extended digits for '''pi''' or '''e''',
<br>a REXX (external) subroutine is used for such purposes so as to not make the program using the constant unwieldy large.
<lang rexx>/*REXX program demonstrates some common trig functions (30 decimal digits are shown).*/
showdigs= 25 /*show only 25 digits of number. */
Line 4,222 ⟶ 4,220:
return Asin(x / sqrt(1 + x*x) )
/*──────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x;
/*──────────────────────────────────────────────────────────────────────────────────────*/
sin:
/*──────────────────────────────────────────────────────────────────────────────────────*/
.sinCos:
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); i=; m.=9; h= d+6
Line 4,255 ⟶ 4,253:
/*John Machin's formula is used for calculating more digits. */</lang>
Programming note:
╔═════════════════════════════════════════════════════════════════════════════╗
║ Functions that are not included here are (among others): ║
║ ║
║ some of the usual higher-math functions normally associated with trig ║
║ functions: POW, GAMMA, LGGAMMA, ERF, ERFC, ROOT, ATAN2, ║
║ LOG (LN), LOG2, LOG10, and all of the ║
║ hyperbolic trigonometric functions and their inverses (too many to list ║
║ here), ║
║ angle conversions/normalizations: degrees/radians/grads/mils: ║
║ a circle ≡ 2 pi radians ≡ 360 degrees ≡ 400 grads ≡ 6400 mils. ║
║ ║
║ Some of the other trigonometric functions are (hyphens added intentionally):║
║ ║
║ CHORD ║
║ COT (co-tangent) ║
║ CSC (co-secant) ║
║ CVC (co-versed cosine) ║
║ CVS (co-versed sine) ║
║ CXS (co-exsecant) ║
║ HAC (haver-cosine) ║
║ HAV (haver-sine ║
║ SEC (secant) ║
║ VCS (versed cosine or ver-cosine) ║
║ VSN (versed sine or ver-sine) ║
║ XCS (ex-secant) ║
║ COS/SIN/TAN cardinal (damped COS/SIN/TAN functions) ║
║ COS/SIN integral ║
║ ║
║ and all pertinent inverses of the above functions (AVSN, ACVS, ···). ║
╚═════════════════════════════════════════════════════════════════════════════╝
{{out|output}}
|