As with comparing two real numbers, it was forbidden to us (back in 1980 while programming in Algol) to do that directly.

We were told to considder two real numbers equal if they 'were close enough together' or when 'their difference was small enough'.

Even now i often have a constant named epsilon with a value often of 0.000001.

I considder two real numbers equal when the absolute value of their difference is smaller than (or equal to) this epsilon.

Ing. C.P.J. de Boer

afd. Datamanagement & Systeembeheer

In theorie is er geen verschil tussen theorie en praktijk. De praktijk is echter anders...

> -----Oorspronkelijk bericht-----

> Van: SPSSX(r) Discussion

> [mailto:

[hidden email]]Namens Richard

> Ristow

> Verzonden: donderdag 22 juni 2006 19:40

> Aan:

[hidden email]
> Onderwerp: Re: Data Rounding

>

>

> At 04:27 AM 6/22/2006, David Millar wrote:

>

> >I had a problem previously when I wanted to compare two

> >rounded/truncated* variables. Although the value for each variable

> >might appear to be the same (e.g. "1.45" or whatever) they

> were stored

> >internally as slightly different numbers. When I used the formats

> >command to see what was stored I'd start to see differences at about

> >the 16th place of decimals. This could present you with a

> problem if,

> >for example, you want to select cases on the basis of the truncated

> >values that appear in SPSS.

>

> Yes; this should be emphasized again and again.

>

> Not all fractions can be represented exactly. (3/2)=1.5 is exact.

> (4/3)=1.3333 is not exact, and it can't be made exact by adding any

> (finite) number of digits.

>

> Now, *which* fractions can be represented exactly, depends on the

> number system. The one SPSS uses(*) isn't the standard decimal

> numbering system, and doesn't have the same set of representable

> fractions.

>

> You can look at the details of the representation your system

> is using,

> but it's not worth the trouble. Besides, the representation is *NOT*

> part of the specifications of the system; it would be reasonable for

> SPSS to switch to another high-precision standard, if that offered

> practical advantages.

>

> The safe rule is: <<There Is No Such Thing as an Exact

> Fraction>>. If a

> number must have a certain value *exactly*, change the scale so that

> value is an integer.

>

> There may well be reasons for "having data rounded in the .sav file to

> the nearest 10th," but be cautious: What does it benefit you?

> Does that

> benefit depend on the numbers rounded values being exact?

> ......................

> Demonstration: SPSS draft output

>

> FORMATS INTEGER (F05)

> /FRACTION (F10.3)

> /SCALE (E08.1).

> DATASET NAME McGoldrick.

> NUMERIC DELTA (E11.3).

> COMPUTE DELTA = INTEGER - (FRACTION*SCALE).

> FORMATS DELTA (E11.3).

> STRING FLAG (A03).

> RECODE DELTA

> (0 = ' ')

> (ELSE = '***') INTO FLAG.

> LIST.

>

> List

> |-------------------------|------------------------|

> |Output Created |22-JUN-2006 16:09:23 |

> |-------------------------|------------------------|

> [McGoldrick]

>

> Integer Fraction Scale DELTA FLAG

>

> 1 .010 1.0E+002 0.000E+000

> 5 .050 1.0E+002 0.000E+000

> 7 .070 1.0E+002 -8.882E-016 ***

> 9 .090 1.0E+002 0.000E+000

> 13 .130 1.0E+002 0.000E+000

> 57 .570 1.0E+002 7.105E-015 ***

> 91 .910 1.0E+002 0.000E+000

> 13 .130 1.0E+002 0.000E+000

> 57 .570 1.0E+002 7.105E-015 ***

> 91 .910 1.0E+002 0.000E+000

> 135 1.350 1.0E+002 0.000E+000

> 579 5.790 1.0E+002 0.000E+000

> 913 9.130 1.0E+002 -1.137E-013 ***

> 1 .001 1.0E+003 0.000E+000

> 5 .005 1.0E+003 0.000E+000

> 7 .007 1.0E+003 0.000E+000

> 9 .009 1.0E+003 0.000E+000

> 13 .013 1.0E+003 0.000E+000

> 57 .057 1.0E+003 0.000E+000

> 91 .091 1.0E+003 0.000E+000

> 135 .135 1.0E+003 0.000E+000

> 579 .579 1.0E+003 0.000E+000

> 913 .913 1.0E+003 0.000E+000

> 1357 1.357 1.0E+003 0.000E+000

> 5791 5.791 1.0E+003 0.000E+000

> 9135 9.135 1.0E+003 0.000E+000

>

> Number of cases read: 26 Number of cases listed: 26

> ......................

> (*) SPSS for Windows uses 64-bit floating-point numbers following

> standard IEEE 754. Likely enough for other platforms, too, but I don't

> know for sure. SPSS uses IEEE 754 because it's a pretty good standard,

> and most computers have hardware made to work with it. Most other

> packages - SAS, I assume Excel, I believe Single and Double datatypes

> in Access - also use it, for the same reasons.

>