Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.std.c Subject: Re: contradiction about the INFINITY macro Date: Mon, 11 Oct 2021 12:39:50 -0700 Organization: None to speak of Lines: 58 Message-ID: <87fst75p15.fsf@nosuchdomain.example.com> References: <20210930012112$48d9@zira.vinc17.org> <87pmsqizrh.fsf@nosuchdomain.example.com> <20210930105413$d6e8@zira.vinc17.org> <86wnmoov7c.fsf@linuxsc.com> <20211009201151$a68b@zira.vinc17.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="d1524f439902674a2af25710c0ea0744"; logging-data="4689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Mk/DJjtS6rGMiIw2rtt36" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:mViuBmpkCilrWS4XjRZHdHlwUCU= sha1:qxIa7BgDOQe3X1zwXq8uqqch7dQ= Xref: csiph.com comp.std.c:6351 James Kuyper writes: > On 10/9/21 4:17 PM, Vincent Lefevre wrote: >> In article <86wnmoov7c.fsf@linuxsc.com>, >> Tim Rentsch wrote: >>> What occurs is defined behavior and (for implementations that do >>> not have the needed value for infinity) violates a constraint. >>> A diagnostic must be produced. >> >> If this is defined behavior, where is the result of an overflow >> defined by the standard? (I can see only 7.12.1p5, but this is >> for math functions; here, this is a constant that overflows.) > > "For decimal floating constants, and also for hexadecimal floating > constants when FLT_RADIX is not a power of 2, 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." (6.4.4.2p3) > > In the case of overflow, for a type that cannot represent infinity, > there is only one "nearest representable value", which is DBL_MAX. But does that apply when a constraint is violated? 6.4.4p2, a constraint, says: Each constant shall have a type and the value of a constant shall be in the range of representable values for its type. A "constraint", aside from triggering a required diagnostic, is a "restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted", which is IMHO a bit vague. My mental model is that if a program violates a constraint and the implementation still accepts it (i.e., the required diagnostic is a non-fatal warning) the program's behavior is undefined -- but the standard doesn't say that. Of course if the implementation rejects the program, it has no behavior. For what it's worth, given this: double too_big = 1e1000; gcc, clang, and tcc all print a warning and set too_big to infinity. That's obviously valid if the behavior is undefined. I think it's also valid if the behavior is defined; the nearest representable value is DBL_MAX, and the larger representable value immediately adjacent to DBL_MAX is infinity. It doesn't seem to me to be particularly useful to say that a program can be rejected, but its behavior is defined if the implementation chooses not to reject it. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */