Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162104

Re: What does (real) number mean?

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: What does (real) number mean?
Date 2021-07-29 17:37 -0400
Organization A noiseless patient Spider
Message-ID <sdv73f$jji$1@dont-email.me> (permalink)
References (1 earlier) <eb3eee1f-fff9-465a-a9bc-b5df32f848b8n@googlegroups.com> <bbe400ff-512d-4984-a88f-1653467992abn@googlegroups.com> <31358abf-a486-48ce-94ef-36616b20086cn@googlegroups.com> <9cf8f398-f885-49a4-ae20-6cb3dc2eb0c6n@googlegroups.com> <87wnp93x2p.fsf@bsb.me.uk>

Show all headers | View raw


On 7/29/21 12:26 PM, Ben Bacarisse wrote:
> wij <wyniijj@gmail.com> writes:
...
>> Precisely, FP is an encoding of number in (binary) scientific notation.
>> Floating-point number almost represents an approximate number.
> 
> It's more accurate to say that floating-point numbers are exact.
> 
>> The error accumulates.
> 
> Yes.  The results of operations (and that includes input and the
> conversion of source-code literals) may not be representable.  Most
> quality implementations will give very tight bounds on the acceptable
> error for each operation.  For example, most implementations will expend
> considerable effort to convert a decimal literal to the nearest
> representable floating point number.


In more detail, here's what the C standard has to say about it:

"The accuracy of the floating-point operations (+, -, *, /) and of the
library functions in <math.h> and <complex.h> that return floating-point
results is implementation-defined, as is the accuracy of the conversion
between floating-point internal representations and string
representations performed by the library functions in <stdio.h>,
<stdlib.h>, and <wchar.h>. The implementation may state that the
accuracy is unknown." (5.2.4.2.2p6)

That means that an implementation could be fully conforming even if it
evaluates subtraction so inaccurately that

    LDBL_MAX - LDBL_MIN < LDBL_MIN - LDBL_MAX

evaluates as "true", so long as it's documentation doesn't claim to
provide any higher degree of accuracy, which would essentially render
floating point math useless. The C standard recommends, and in some
contexts, requires that conversions be correctly rounded, which means:

"representation in the result format that is nearest in value, subject
to the current rounding mode, to what the result would be given
unlimited range and precision" (3.9)

which is pretty much the strongest possible requirement, but that is
nearly useless unless floating point arithmetic also has fairly strong
accuracy requirements.

However, when __STDC_IEC_559__ is pre-#defined by the implementation,
the much stronger requirements of IEC 60559 (== ANSI/IEEE 754) apply,
and in that case floating point math is very useful (though care is
still required when using it).

That's why Ben referred to "quality implementations" - such
implementations will provide accuracy much better than the minimum
allowed by the C standard.

Back to comp.lang.c | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

What does (real) number mean? wij <wyniijj@gmail.com> - 2021-07-27 08:40 -0700
  Re: What does (real) number mean? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-27 10:52 -0700
    Re: What does (real) number mean? wij <wyniijj@gmail.com> - 2021-07-27 16:14 -0700
  Re: What does (real) number mean? "minf...@arcor.de" <minforth@arcor.de> - 2021-07-28 00:24 -0700
    Re: What does (real) number mean? wij <wyniijj@gmail.com> - 2021-07-29 03:00 -0700
      Re: What does (real) number mean? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-07-29 03:11 -0700
        Re: What does (real) number mean? wij <wyniijj@gmail.com> - 2021-07-29 09:21 -0700
          Re: What does (real) number mean? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-29 17:26 +0100
            Re: What does (real) number mean? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-29 17:37 -0400

csiph-web