Suppose that we say:
double three = 3.0;
double point3 = 0.3;
What can we say about the stored values?

  • A: Both values are represented exactly.
  • B: Both values are represented approximately.
  • C: three is exact, point3 is approximate.
  • D: three is approximate, point3 is exact.
  • E: Depends on which CPU chip is used.

    Answer: C

    Integers are represented exactly in floating point, up to the limits of the mantissa accuracy (about 15 digits for double).

    Decimal fractions usually cannot be represented exactly in binary. Just as 1/3 = .3333333... in decimal, 1/10 is an infinitely repeating pattern in binary. Therefore, any floating-point number with nonzero digits after the decimal is probably represented as an approximation in binary.

    Floating point representation is governed by an IEEE Standard, which all CPU chips follow. Therefore, the representation of a floating-point value will be the same no matter which CPU chip is used.

    Page-10    Prev    Next    Page+10