Talk:Trigonometric functions: Difference between revisions

Notes on precise sin implemented in Rexx
(Notes on precise sin implemented in Rexx)
Line 16:
I was trying to add code for IDL, but the "pre" tag doesn't seem to work quite like I expected. Can someone clarify?
: Mediawiki's way of handling "pre" is broken. Try surrounding the "pre" block with <nowiki>/</nowiki>. --[[User:Short Circuit|Short Circuit]] 01:00, 2 May 2008 (MDT)
 
 
== Notes on precise sin implemented in Rexx ==
 
One of THE features of Rexx is the virtually unlimited numeric precision.
Now if you want to get sin(0.1) with 30 precise digits
(for whatever reason)
 
With Numeric Digits 30
sin as implemented in REXX trigonometric functions yields
0.0998334166468281523068141984103
The implementation of sin in ooRexx' rxmath function yields
0.09983341664682816 (this is restricted to 16 digits!)
when the precise value (50 digits) is
0.099833416646828152306814198410622026989915388017978
which should be rounded to
0.0998334166468281523068141984106
 
so both implementations above have an incorrect last digit
 
A possible remedy is to compute the function with a higher precision
and then round the result to the desired one
 
ps=0.09983341664682815230681419841062199
0.0998334166468281523068141984106
 
These lines come from
pSIN: procedure
/****************************************************************
* Calculate sin(x) to the specified precision
****************************************************************/
parse arg X, P
Numeric Digits (p+2)
ps=sin(x)
Say 'ps='ps
Numeric Digits p
Say ' '||(ps+0)
Return ps+0
 
--[[User:Walterpachl|Walterpachl]] 19:43, 22 June 2012 (UTC)
 
Of course the Rexx implementation of sin could compute tthis higher precision and round it upon returning the value
 
I discussed this topic 10 years ago on Vladimir Zabrovsky's Album of (Rexx) algorithms which contains a wealth of code.
2,295

edits