03-30-2016, 04:43 PM (This post was last modified: 03-30-2016 04:58 PM by Claudio L..)
Post: #247
 Claudio L. Senior Member Posts: 1,794 Joined: Dec 2013
(03-29-2016 05:20 PM)Visitor Wrote:  Hello Claudio,

in dectranscen.c many constants (e.g. decconst_PI() ) are given back with twice the precision as set
due to shift right of only 2
Code:
 int nwords=253-((Context.precdigits+7)>>2);

is that intended?

currently a side effect will be that with the default settings (32 digits) if I enter pi0 i get back pi with almost 70 digits (instead of 32)

shouldn't the constant being rounded before pushing it to the display?

if I multiply this longer number by 1 it will be rounded to the system precision.

BTW I'm admiring your work and the time you are putting into this project. I just came recently across this project and am very excited of it.

regards

Martin

I'm glad somebody is actually looking at the code. And understanding it despite my bad coding habits too!
Jokes aside, yes, it is intended. Most of those constants are for internal use by the trig and hyperbolic functions, therefore they need some extra precision to guarantee that the final result has enough digits.
Case in point: the PI constant is used for argument reduction among other things. If an angle is exactly the same as PI with 32 digits precision, the angle it represents is not exactly PI, but only the first 32 digits of PI. We need the internal PI to have at least twice the digits, so that when subtracting PI0-angle we get at least 32 significant digits for the angle we'll be using as input to SIN or COS to have any meaning.
For example:
π0 SIN gives a meaningless result, because the input is too close to PI at double precision, and the system fails to produce an accurate result.
EDIT: That result is not totally meaningless, it's actually accurate up to a few guard digits (usually 8). Just do π0 SIN π0 GETPREC 2 * SETPREC π0 - + and you'll get that only the first 8 digits were correct.

The Pi0 constant was exposed to the user for those corner cases. Quite often you need PI at a higher precision than normal so subtractions work well for angles near PI. Notice the 0 in the name, to make it different from the regular PI constant.
As you noticed, operations will round the result to the system precision, and that's the important part: it's the result that's rounded, but never the arguments! The operation will take place using the arguments as given, only the final result will be rounded.
 « Next Oldest | Next Newest »