Talk:Trigonometric functions: Difference between revisions

explain why I want sin(x,unit,precision)
m (→‎Notes on precise sin implemented in Rexx: added the word ''decimal'' in front of digits (for precision) to help clarify what kind of digits. -- ~~~~)
(explain why I want sin(x,unit,precision))
Line 89:
.</lang>
This isn't probably the best forum to discuss these types of code (result) minutia when code is taken out of context or the modified code or driver code isn't shown to verify your results. I can be contacted via E-mail to iron out these details before large amounts of chatter are posted. -- [[User:Gerard Schildberger|Gerard Schildberger]] 20:55, 22 June 2012 (UTC)
----
It IS! I wanted to point out a problem and its solution.
I don't think people want to understand the huge driver and its details (SHOWDIGS)
but rather want to use the functions offered for their task.
 
I did not modify anything!
Just took sin (and the routines used by it) out of the rosetta-box
and used it in my program as follows:
/lang=rexx>
Numeric Digits 30
Say sin(0.1)
Numeric Digits 32
Say sin(0.1)
Exit
/******* procedures ex REXX trigonometric functions ***************************/
sin: procedure; arg x; x=r2r(x); numeric fuzz min(5,digits()-3)
if abs(x)=pi() 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
r2r: return arg(1)//(2*pi()) /*normalize radians?1 unit circle*/
pi: return, /*a bit of overkill, but hey !! */
3.1415926535897932384626433832795028841971693993751058209749445923078164062862
</lang>
The output is
<pre>
0.0998334166468281523068141984103
0.099833416646828152306814198410619
</pre>
What I want is that the first call gives me the 30 correct digits.
This can be done by internally (in sin) raise the precision and return theresult rounded to the desired precision.
 
Note that external funtions don't inherit the caller's precision,
so having an extra (optional) argument p is an option.
Also the possiblity of x in sin(x) is radians or degrees is a useful extension implemented in the ooRexx function package.
--[[User:Walterpachl|Walterpachl]] 07:13, 23 June 2012 (UTC)
2,295

edits