Re: wprintf() and large exact floats?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Vincent Fatica" <vince@xxxxxxxxxxxxxxxxx> wrote in message news:47fbe50a$1@xxxxxxxxxxxxxxxxxxxx

2^57 can be (and is) exactly represented as a double...

It is almost always a mistake to think of floating point representations to a fixed number of decimals as "exact". To be exact a decimal needs to specify an infinite number of decimal places. If you think of a number with an infinite number of trailing zeroes after (say) 16 specified significant figures as being "exactly" represented, then you'll end up in trouble more often than not. (The idea that the trailing digits, beyond those stored by the computer, must be zero, is a poor one. Think of them as unknown.)

In decimal representations 2.0 2.00 2.000 2.0000 are different objects, each of which is a number known to lie in a (different) range around the integer 2.

Computers of course cannot make this distinction at this level, but the problem does come in at around the 16th significant figure for doubles.

The point is that you have no right to assume that arithmetic involving floating point representations can ever be exact.

If you want to store an integer exactly, then do not use floating point types.

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

.



Relevant Pages

  • Re: pop-forum loop termination with floats
    ... > because the representation of decimals is not exact. ... your later message) expect consistency from exact tests on floats. ... point representations and processing are defined by a standard. ...
    (comp.lang.pop)
  • Re: Switch for floating !!
    ... Floating point representations are exact. ... If you convert 0.1 to float and then back to double, ...
    (comp.lang.c)
  • Re: Possreps and numeric types
    ... tell my calculator that I have 12 volts running across a 3 ohm ... I have no problem with them using floating point as long as the error is a small fraction of a penny. ... I don't recall suggesting that exact calculations have no utility. ... I merely acknowledged that representations of rationals are approximations representing very small ranges of values. ...
    (comp.databases.theory)
  • Re: floating point display problem
    ... Floating point numbers aren't exact. ... Even though 7 decimals digits is less than 52 bits, ... representation of a floating-point number to the internal IEEE 754 ...
    (comp.lang.java.programmer)
  • Re: floating point display problem
    ... Floating point numbers aren't exact. ... from guaranteed that a 7 decimals number can be represented exact ... representation of a floating-point number to the internal IEEE 754 ...
    (comp.lang.java.programmer)