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: Fri, 08 Oct 2021 11:40:09 -0700 Organization: None to speak of Lines: 39 Message-ID: <878rz3743a.fsf@nosuchdomain.example.com> References: <20210930012112$48d9@zira.vinc17.org> <87pmsqizrh.fsf@nosuchdomain.example.com> <20210930105413$d6e8@zira.vinc17.org> <87lf3ehy4v.fsf@nosuchdomain.example.com> <20211001083755$efb3@zira.vinc17.org> <86sfxbpm9d.fsf@linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="41139519b557a828e82b1a9dc12922fd"; logging-data="24327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cZehLj9NZ9HIDdJoGw/I2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:Pw/w+F3lRCGRKBpX18+8W9DpTcM= sha1:joKgv7eQwI/wUjImidRL4BHPCkg= Xref: csiph.com comp.std.c:6340 Tim Rentsch writes: > Vincent Lefevre writes: [...] >> Shouldn't the standard by changed to make INFINITY conditionally >> defined (if not required to expand to a true infinity)? [...] > > To me it seems better for INFINITY to be defined as it is rather > than being conditionally defined. If what is needed is really an > infinite value, just write INFINITY and the code either works or > compiling it gives a diagnostic. If what is needed is just a very > large value, write HUGE_VAL (or HUGE_VALF or HUGE_VALL, depending) > and the code works whether infinite floating-point values are > supported or not. If it's important that infinite values be > supported but we don't want to risk a compilation failure, use > HUGE_VAL combined with an assertion > > assert( HUGE_VAL == HUGE_VAL/2 ); > > Alternatively, use INFINITY only in one small .c file, and give > other sources a make dependency for a successful compilation > (with of course a -pedantic-errors option) of that .c file. I > don't see that having INFINITY be conditionally defined buys > anything, except to more or less force use of #if/#else/#endif > blocks in the preprocessor. I don't mind using the preprocessor > when there is a good reason to do so, but here I don't see one. I don't see how that's better than conditionally defining INFINITY. If you really need an infinite value, just write INFINITY and the code either works or compiling it gives a *clearer* diagnostic for the undeclared identifier. If you need to test whether infinities are supported, #ifdef INFINITY is a lot clearer than assert( HUGE_VAL == HUGE_VAL/2 ). -- 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 */