Post Reply 
A quick precision test
06-04-2014, 02:17 PM (This post was last modified: 06-04-2014 02:20 PM by Claudio L..)
Post: #35
RE: A quick precision test
(06-04-2014 01:38 PM)pito Wrote:  Not sure whether doing 27 times x^2 or using Xpower2power27 is the same. Power functions are calculated in a different way usually (less precise I bet..).

I've calculated the stuff with my dusty vanilla decnum code (DECNUMDIGITS 34) and get:

Code:
// 27x x^2 TEST
cout<<"27xTEST"<<endl;
x = "1.0000001";
timer = millis;
for (i=1; i<=27; i++) {
  x = x * x;
}
timer = millis - timer;
cout<<"27xTest = "<<x<<endl;
cout<<"Elapsed x1 = "<<timer<<" ms"<<endl;

Code:
27xTEST
27xTest = 674530.4707410845593826891847277722
Elapsed x1 = 6 ms

Regarding your suspicion that it's not the same: you are right, it's not.
The power function is guaranteed to give you an accurate result with 34 good digits, for any 2 parameters (in this case, your guess that it's less precise is incorrect).
Doing 2 ^ 27, the result is less than 34 digits, so it's exact (no rounding error).
so 1.0000001 ^ (2^27) should give you an answer with all 34 digits correct, since both numbers are "exact" as given in the problem.

I don't know how decNumber does it in particular, but in general powers with small integer exponents are handled by a sequence of multiplications, while powers of real numbers or large numbers are usually done through logarithms:

Code:
x^a = exp( a * ln(x) )

Which is usually very accurate, as ln() and exp() are both guaranteed to give you 34+GUARD good digits on any number you throw at them.

If you assume that basic operations give you results that are guaranteed up to your user precision, your only source of error is the rounding of those results to your user precision. The less operations you perform the better, so you don't accumulate those rounding errors.

In this case, if you do:
Code:
 1.0000001 LN 2 27 ^ * EXP
You get the same result as doing
Code:
 1.0000001 2 27 ^ ^

but this is by pure chance (with this precision, this particular number behaves like this), since the intermediate rounded results of LN and * could've messed the last digit.

Claudio
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
A quick precision test - pito - 06-02-2014, 10:37 PM
RE: A quick precison test - Paul Dale - 06-02-2014, 11:04 PM
RE: A quick precison test - pito - 06-03-2014, 12:07 AM
RE: A quick precison test - Paul Dale - 06-03-2014, 12:13 AM
RE: A quick precison test - pito - 06-03-2014, 12:27 AM
RE: A quick precison test - Paul Dale - 06-03-2014, 12:36 AM
RE: A quick precision test - Claudio L. - 06-04-2014, 01:25 PM
RE: A quick precision test - walter b - 06-04-2014, 01:33 PM
RE: A quick precision test - Claudio L. - 06-04-2014, 01:42 PM
RE: A quick precision test - Paul Dale - 06-04-2014, 09:47 PM
RE: A quick precison test - walter b - 06-03-2014, 11:24 AM
RE: A quick precision test - Dieter - 06-04-2014, 01:08 PM
RE: A quick precision test - walter b - 06-04-2014, 01:23 PM
RE: A quick precison test - HP67 - 06-03-2014, 09:06 AM
RE: A quick precision test - everettr - 06-03-2014, 02:11 PM
RE: A quick precison test - pito - 06-03-2014, 07:23 AM
RE: A quick precison test - HP67 - 06-03-2014, 11:50 AM
RE: A quick precison test - Paul Dale - 06-03-2014, 12:25 PM
RE: A quick precision test - walter b - 06-03-2014, 01:52 PM
RE: A quick precision test - Paul Dale - 06-03-2014, 10:10 PM
RE: A quick precison test - HP67 - 06-03-2014, 12:41 PM
RE: A quick precision test - HP67 - 06-03-2014, 01:01 PM
RE: A quick precision test - walter b - 06-03-2014, 01:56 PM
RE: A quick precision test - pito - 06-04-2014, 01:38 PM
RE: A quick precision test - Claudio L. - 06-04-2014 02:17 PM
RE: A quick precision test - Paul Dale - 06-04-2014, 10:09 PM
RE: A quick precision test - Claudio L. - 06-05-2014, 01:18 AM
RE: A quick precision test - Paul Dale - 06-05-2014, 02:00 AM
RE: A quick precision test - Claudio L. - 06-05-2014, 11:03 AM
RE: A quick precision test - Dieter - 06-05-2014, 11:23 AM
RE: A quick precision test - Paul Dale - 06-05-2014, 12:06 PM
RE: A quick precision test - Claudio L. - 06-05-2014, 09:08 PM
RE: A quick precision test - Paul Dale - 06-05-2014, 10:09 PM
RE: A quick precision test - Claudio L. - 06-06-2014, 12:57 AM
RE: A quick precision test - Claudio L. - 06-06-2014, 01:15 AM
RE: A quick precision test - Paul Dale - 06-06-2014, 01:35 AM
RE: A quick precision test - pito - 06-06-2014, 11:16 AM
RE: A quick precision test - Claudio L. - 06-06-2014, 12:04 PM
RE: A quick precision test - Paul Dale - 06-06-2014, 10:55 PM
RE: A quick precision test - pito - 06-07-2014, 11:56 AM
RE: A quick precision test - Paul Dale - 06-07-2014, 12:20 PM
RE: A quick precision test - pito - 06-07-2014, 04:44 PM
RE: A quick precision test - walter b - 06-08-2014, 05:28 PM
RE: A quick precision test - Claudio L. - 06-05-2014, 09:25 PM
RE: A quick precision test - Paul Dale - 06-05-2014, 10:20 PM
RE: A quick precision test - Claudio L. - 06-06-2014, 01:03 AM
RE: A quick precision test - Paul Dale - 06-06-2014, 01:46 AM
RE: A quick precision test - pito - 06-04-2014, 02:12 PM
RE: A quick precision test - pito - 06-04-2014, 02:31 PM
RE: A quick precision test - pito - 06-05-2014, 08:49 PM
RE: A quick precision test - walter b - 06-05-2014, 09:07 PM
RE: A quick precision test - pito - 06-05-2014, 09:13 PM
RE: A quick precision test - Mark Hardman - 06-05-2014, 09:21 PM
RE: A quick precision test - pito - 06-06-2014, 12:19 PM
RE: A quick precision test - pito - 06-08-2014, 12:44 PM
RE: A quick precision test - walter b - 06-08-2014, 01:57 PM
RE: A quick precision test - pito - 06-08-2014, 02:07 PM
RE: A quick precision test - walter b - 06-08-2014, 03:00 PM
RE: A quick precision test - Paul Dale - 06-08-2014, 10:46 PM



User(s) browsing this thread: 20 Guest(s)