Anonymous user
Trigonometric functions: Difference between revisions
→{{header|REXX}}: updated program code, elided STYLE from PRE html tag.
Walterpachl (talk | contribs) (→{{header|ooRexx}}: added routine rxmhelp to rxm.cls) |
(→{{header|REXX}}: updated program code, elided STYLE from PRE html tag.) |
||
Line 3,134:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────subroutines─────────────────────────*/
Asin: procedure; parse arg x 1 z 1 o 1 p;
do j=2 by 2 until p=z; p=z; o=o*aa*(j-1)/j; z=z+o/(j+1); end
return z /* [↑] compute until no noise.*/
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(9,digits()-9)
Line 3,147 ⟶ 3,148:
return .sinCos(1,1,-1)
sin: procedure; parse arg x; x=r2r(x); numeric fuzz
if abs(x)=pi | x=0 then return 0; return .sinCos(x, x, +1)
.sinCos: parse arg z 1 p,_,i; x=x*x
do k=2 by 2; _=-_*x/(k*(k+i));z=z+_;if z=p then leave;p=z;end; return z
sqrt: procedure; parse arg x,i; if x=0
parse value format(x,2,1,,0) 'E0' with g 'E' _ .;
do j=
do k=j+5 to 0 by -1;
g=.5*(g+x/g); end
e: return,
2.7182818284590452353602874713526624977572470936999595749669676277240766303535
Line 3,176 ⟶ 3,179:
/*If more than 1 million digits are required, be patient. */
$fuzz: return min(arg(1), max(1, digits() - arg(2) ) )
Acos: procedure; parse arg x; if x<-1|x>1 then call AcosErr; return .5*pi()-Asin(x)
AcosD: return r2d(Acos(arg(1)))
Line 3,183 ⟶ 3,187:
tan: procedure; parse arg x; _=cos(x); if _=0 then call tanErr; return sin(x)/_
tanD: return tan(d2r(arg(1)))
d2d: return arg(1) //
d2r: return r2r(d2d(arg(1))*pi() /180)
r2d: return d2d((arg(1)*180 /pi()))
r2r: return arg(1) // (pi()*2)
show: return left(left('',arg(1)>=0)format(arg(1),,showdigs)/1,showdigs)
tellErr: say; say '*** error! ***'; say; say arg(1); say; exit 13
Line 3,194 ⟶ 3,198:
sqrtErr: call tellErr "sqrt(x), X can't be negative, X="||x
/* ┌───────────────────────────────────────────────────────────────┐
│ Not included here are: (among others):
│ some of the usual higher-math functions normally associated │
│ with trig functions: POW, GAMMA, LGGAMMA, ERF, ERFC, ROOT, │
Line 3,202 ⟶ 3,206:
│ Angle conversions/normalizations: degrees/radians/grads/mils │
│ [a circle = 2 pi radians, 360 degrees, 400 grads, 6400 mils].│
│ Some of the other trig functions
│ CHORD │
│ COT (co-tangent) │
Line 3,221 ⟶ 3,224:
└───────────────────────────────────────────────────────────────┘ */</lang>
'''output'''
<pre>
Using 30 decimal digits precision.
|