Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Question about floating point precision


From   Markus Hahn <[email protected]>
To   [email protected]
Subject   st: Question about floating point precision
Date   Tue, 30 Mar 2010 16:37:01 +1100

Quite often here on Statalist, there are questions regarding the
precision of numbers in Stata. I thought it is again time for such a
question. Although I am aware of most of the issues Stata (or computers
in general) have with the precision of floating point numbers, there is
still (at least) one open question that I have.

Consider the following example (just ignore for a moment that I could
have used '1/2' instead of '26.07/52.14'):

----------------------------------
. // why is this code more precise
. 
. di %22.18f 1559*26.07/52.14
779.500000000000000000

. 
. // than this code
. 
. di %22.18f 1559*26.07
 4.064313000000000e+04

. di %22.18f 40643.13/52.14
779.499999999999890000
----------------------------------

Why is the code in the first part of my example more precise than the
last part? Is it really more precise or does it only SEEM to be so? What
I would like to know is whether the first part is more precise (if at
all) because it only uses one expression for the calculation as compared
to last part which uses two expressions? Does the indirect calculation
introduce this imprecision? 

Markus

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index