[Cfp-interest 2245] nextup/nextdown and HUGE_VAL definition

Vincent Lefevre vincent at vinc17.net
Fri Oct 29 04:37:17 PDT 2021


The current C2x draft (N2731) says:

  7.12.11.5 The nextup functions

  The nextup functions determine the next representable value, in
  the type of the function, greater than x. [...] nextup(HUGE_VAL)
  is HUGE_VAL.

(with symmetric text for nextdown).

Shouldn't the first sentence add something like "or equal to x
if x is the maximum value (of the type)"?

I suppose that it is the intent of "nextup(HUGE_VAL) is HUGE_VAL.",
but this is not completely clear. Note in particular that this could
be interpreted as required only for HUGE_VAL (i.e. for double, but
not necessarily for nextupf(HUGE_VALF) and nextupl(HUGE_VALL)).
Moreover, if this means that HUGE_VAL is the maximum value for the
double type, the other parts of the standard are written like this
were not necessarily the case. Or does this mean that HUGE_VAL is
an exception to the general rule for nextup? (I hope not.)

So, IMHO, it would be simpler to add "or equal to x if x is the
maximum value (of the type)" and remove the sentence on HUGE_VAL
(which is incorrect if HUGE_VAL is not the maximum value).

If HUGE_VAL, HUGE_VALF and HUGE_VALL are expected to be the maximum
values of the type, then the standard should be modified everywhere
it suggests that this isn't necessarily the case. (Note that for the
decimal types, the associated macros expand to positive infinity, so
that they are OK.) This includes:

  7.12 Mathematics <math.h>
[...]
  5   The macro
            HUGE_VAL
      expands to a positive double constant expression, not
      necessarily representable as a float. [...]

  245) HUGE_VAL, HUGE_VALF, and HUGE_VALL can be positive infinities
  in an implementation that supports infinities.

i.e. it currently doesn't require it to be the maximum value, even
on implementations that support infinities. Thus this would need to
be changed.

And also

  F.10 Mathematics <math.h> and <tgmath.h>
[...]
  2   The Standard C macro HUGE_VAL and its float and long double
      analogs, HUGE_VALF and HUGE_VALL, expand to expressions whose
      values are positive infinities.

could be removed as part of the new general definition.

The question is whether this would break existing implementations.

-- 
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