Author Topic: Why do the number not sum to one?  (Read 10600 times)

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2291
    • View Profile
Why do the number not sum to one?
« on: October 22, 2012, 16:22:03 »
HUGIN uses floating point to support the representation and use of real numbers (e.g., probabilities), see e.g., On the wiki-page there is useful information on the use of floating point and its limitations.

In floating point a real number is represented using a (limited) number of significant digits. The number of significant digits depends on the data type used to represent a real number, i.e., the precision. In HUGIN we use either single (4 bytes) or double precision (8 bytes).

In single precision you have 7 significant digits. This means that single precision has sufficiently many digits to store, for instance, the number 0.1234567 in a variable with seven significant digits. A number such as 0.99999999 is, on the other hand, rounded to 1 and if you add 0.00000001, the number 0.00000001 is lost due to the limited precision (only seven significant digits).

As an example consider using HUGIN ActiveX server (single precision) in Excel to add the numbers above (i.e, 0.99999999 + 0.00000001). If Excel uses double precision, the sum becomes 1.00000001 (due to the fact that 0.99999999 is rounded to 1 by HUGIN due to the single precision nature of the HUGIN ActiveX server).

There are other examples which cannot be solved. For instance, consider computing the sum 1/3 + 1/3 + 1/3 using floating point in any (finite) precision. This will never sum to one no matter how many digits of precision you have. Thus, in a computer probabilities do not always sum to one.