[Cfp-interest 2246] meaning of "nearest" in case of overflow

Vincent Lefevre vincent at vinc17.net
Fri Oct 29 06:31:51 PDT 2021


In IEEE 754, there is a special rule for the rounding to nearest in
case of overflow:

  4.3.1 Rounding-direction attributes to nearest

  In the following two rounding-direction attributes, an infinitely
  precise result with magnitude at least b^emax × (b − ½b^(1−p))
  shall round to ∞ with no change in sign [...]

But in the C2x draft (N2731), there is no explicit meaning and there
may be disagreements. For instance:

  3.9
  correctly rounded result

  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

Note that "correctly rounded" is used even in contexts that do not
imply IEEE 754 support. So it is not clear whether the IEEE 754 rule
should be used.

  6.4.4.2 Floating constants
[...]
  4   [...] the result is either the nearest representable value,
      or the larger or smaller representable value immediately
      adjacent to the nearest representable value, chosen in an
      implementation-defined manner. For hexadecimal floating
      constants when FLT_RADIX is a power of 2, the result is
      correctly rounded.

In the last sentence, I would expect the IEEE 754 rule, though there
is no mention of IEEE 754 (this rule remains valid without IEEE 754
support).

And about "nearest representable value" earlier, in case of overflow
(i.e. an inexact ∞ result for IEEE 754), the question is whether the
C standard means also ∞ or the largest finite value (e.g. DBL_MAX for
the double type), i.e. whether nextdown(DBL_MAX) is an acceptable
result (as being adjacent to DBL_MAX if DBL_MAX is assumed to be the
nearest representable value) or not.

For the context:

In https://groups.google.com/g/comp.std.c/c/XCzEiwD9n_A/m/Q7XScZMoBAAJ
(2021-10-26 18:53:34), James Kuyper says:
> No definition by the standard is needed; the conventional mathematical
> definitions of "nearest" are sufficient. If infinity is representable,
> DBL_MAX is always nearer to any finite value than infinity is.
> Regardless of whether infinity is representable, any finite value
> greater than DBL_MAX is closer to DBL_MAX than it is to any other
> representable value.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list