Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.std.c Subject: Re: contradiction about the INFINITY macro Date: Thu, 30 Sep 2021 03:20:23 +0100 Organization: A noiseless patient Spider Lines: 32 Message-ID: <87a6jun6s8.fsf@bsb.me.uk> References: <20210930012112$48d9@zira.vinc17.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="50d1fb071442832dba5b87e100f83a1a"; logging-data="14035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+ZV6hFyQ24qsBld24ZOmH5NO2p5zpveM=" Cancel-Lock: sha1:NmP6EeV+BsqH/Oreb8t6tO6aWTg= sha1:H2nPsrYGcHldJtVhqkbB9wOZsAU= X-BSB-Auth: 1.60262bb36d5e89f07070.20210930032023BST.87a6jun6s8.fsf@bsb.me.uk Xref: csiph.com comp.std.c:6323 Vincent Lefevre writes: > In ISO C99:TC3 to C17, 7.12p4: > > The macro INFINITY expands to a constant expression of type float > representing positive or unsigned infinity, if available; else to a > positive constant of type float that overflows at translation time. > > Consider the "else" case. It is said that INFINITY expands to a > constant and that it overflows, so that it is not in the range of > representable values of float. > > But in 6.4.4p2: > > Each constant shall have a type and the value of a constant shall > be in the range of representable values for its type. > > which would imply that INFINITY expands to a value in the range of > representable values of float, contradicted by 7.12p4. Right. But there is footnote that clarifies matters: "In this case, using INFINITY will violate the constraint in 6.4.4 and thus require a diagnostic." so any program using INFINITY has undefined behaviour because the intent is to violate 6.4.4. I agree that there should be a better way to specify it, but expanding to a constant that violates the constraints on such constants is clumsy but reasonably clear. -- Ben.