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

 From "Austin Nichols" To statalist@hsphsun2.harvard.edu Subject Re: st: Precision issues with double storage type (??) Date Tue, 7 Aug 2007 08:57:25 -0400

```Hiroshi Maeda <hmaeda1@uic.edu>:
Maarten has already indicated how to avoid the precision problems you
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:

clear
set type double
input id dep pay ref
1   61.42   21.30   40.12
2   69.00   68.49    0.51
end
set type float
foreach v in dep pay ref {
g f`v'=`v'
}
d
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 <hmaeda1@uic.edu> 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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```