Anonymous user
Euler's identity: Difference between revisions
m
→{{header|REXX}}: simplified cos, sin, sqrt functions, added whitespace.
m (→{{header|REXX}}: simplified cos, sin, sqrt functions, added whitespace.) |
|||
Line 518:
<br>program.
<lang rexx>/*REXX program proves Euler's identity by showing that: e^(i pi) + 1 ≡ 0 */
numeric digits length( pi() ) -
say ' cos(pi) = '
say ' sin(pi) = '
say /*separate the wheat from the chaff. */
say ' e^(i pi) + 1 = ' fmt($) '
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fmt: procedure; parse arg x; x= format(x, , digits() %2, 0); return left('', x>=0)x /
mult: procedure; parse arg a,b; if a=0 | b=0 then return 0; return a*b
pi: pi= 3.1415926535897932384626433832795028841971693993751058209749445923; return pi
/*──────────────────────────────────────────────────────────────────────────────────────*/
numeric digits; numeric form; if x<0 then do; x= -x; i=
parse value format(x, 2, 1, , 0) 'E0' with g 'E' _ .; g= g * .5'e'_ % 2
{{out|output|text= when using the internal default input:}}
<pre>
cos(pi) = -1
sin(pi) = 0
e^(i pi) + 1 = 0 proven
</pre>
|