Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: Question about floating point precision

From   Phil Schumm <>
Subject   Re: st: Question about floating point precision
Date   Tue, 30 Mar 2010 05:04:01 -0500

On Mar 30, 2010, at 12:37 AM, Markus Hahn wrote:
. // why is this code more precise
. di %22.18f 1559*26.07/52.14

. // than this code
. di %22.18f 1559*26.07

. di %22.18f 40643.13/52.14

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?

The difference is due to the order of operations -- remember, / comes before *. To wit:

. di %21x 1559*26.07/52.14

. di %21x (1559*26.07)/52.14

. di %21x 40643.13/52.14

-- Phil

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index