Re: Float comparison



Keith Thompson wrote:
CBFalconer <cbfalconer@xxxxxxxxx> writes:
Keith Thompson wrote:
... snip ...
A stored value of type double cannot represent the real value
1.0+DBL_EPSILON/2.0, any more than a stored value of type int
can represent the value 1.5.
So what? doubles are used to store reals, more or less. ints are
used to store integers. 1.0+DBL_EPSILON/2.0 is a real[1]. 1.5 is
NOT an integer.

[1] but not a storable real, in a double.

It's that "more or less" that bites you, isn't it? Your model makes
some sense if you ignore those pesky details where it falls apart.

<snip>

In addition doubles *are* used to store exact integral values and integer types *are* used to store approximations. Any claim that you have stored a range when you have in fact stored the exact value that you intended to store is clearly wrong and would make error analysis impossible.

Have you read C99 5.2.4.2.2 paragraphs 1-2? (In PDF or hard copy;
plain text doesn't show the formula.) Do you understand what it
means?

The model tells you whether you can store the exact values you would like to store (when that is what you want to do).

Please do not post a followup to this article without quoting and
responding to the previous paragraph, starting with "Have you read".

Yes, it would be helpful if CBF did not ignore most of the points being made.
--
Flash Gordon
.



Relevant Pages

  • Re: Float comparison
    ... Oh, it exists, but not in that floating representation. ... Keith has already mentioned the need to do an error analysis if you want to know what the possible error. ... I know of code which carefully uses doubles to do integer arithmetic, staying within the range where integers can be represented exactly, in order to use the greater range of exact integral values that a double can represent on that specific implementation than an int. ... So either integer types cannot store exact values and you need to do a full error analysis to determine the range of values they might represent or floating point variables can store exact values which are exactly the mathematically correct values the program is intended to store. ...
    (comp.lang.c)
  • Re: Storing array of double. There must be an easier way.
    ... You can use GetChunk & AppendChunk methods of Field (ADO) object. ... > I would like to gather a sample of data, which consists of 5,000 doubles. ... I would store the data in a single field in a database. ...
    (microsoft.public.data.ado)
  • Re: Float comparison
    ... In addition doubles *are* used to store exact integral values ... that taken in isolation you do NOT know ... your claim that the values stored are always approximations. ...
    (comp.lang.c)
  • Re: Float comparison
    ... In addition doubles *are* used to store exact integral values ... that taken in isolation you do NOT know ... your claim that the values stored are always approximations. ...
    (comp.lang.c)
  • Re: Float comparison
    ... In addition doubles *are* used to store exact integral values ... that taken in isolation you do NOT know that it is a range. ... The standard actually talks about values that "can be represented exactly" in section 6.3.1.5. ...
    (comp.lang.c)