[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Precision issues with double storage type (??)

From   "Austin Nichols" <>
Subject   Re: st: Precision issues with double storage type (??)
Date   Tue, 7 Aug 2007 08:57:25 -0400

Hiroshi Maeda <>:
Maarten has already indicated how to avoid the precision problems you
are encountering, and where to read more about them.  Keith has
indicated that double precision does not guarantee that sums and
differences will work out exactly (if fractions cannot be represented
perfectly in binary numbers).  Here is another way of expressing your
example that demonstrates (among other things) that
float(x)-float(y)!= float(x-y) in general:

set type double
input id dep pay ref
  1   61.42   21.30   40.12
  2   69.00   68.49    0.51
set type float
foreach v in dep pay ref {
 g f`v'=`v'
g c1=1 if float(fdep)==float(fpay)+float(fref)
g c2=1 if float(fdep)==float(fpay+fref)
li, noo
di %22.16f dep[1], %22.16f pay[1], %22.16f dep[1]-pay[1]
di %22.16f ref[1], %22.16f dep[1]-pay[1]
di %22.16f 40.12, %22.16f dep[1]-pay[1]

On 8/6/07, Hiroshi Maeda <> wrote:
> I am puzzled by the discrepancies between what I expect Stata to do and
> what it actually does, and I suspect storage/precision issues have
> something to do with it. Before you castigate me for beating this dead
> horse yet once again, please note that I have read relevant manual
> entries ([U] 13.10 Precision and problems therein) and statalist
> postings and that I encounter this problem even when numeric variables
> with fractions are stored in -double-
*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index