Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #82734

Re: 1.0 / 0.0

From Manfred <noname@invalid.add>
Newsgroups comp.lang.c++
Subject Re: 1.0 / 0.0
Date 2022-01-04 20:49 +0100
Organization Aioe.org NNTP Server
Message-ID <sr28cb$1h2f$1@gioia.aioe.org> (permalink)
References (7 earlier) <squb43$2oi$1@redfloyd.dont-email.me> <sqvsgu$t98$1@gioia.aioe.org> <664f77e6-54b0-44f7-b074-26aa2e24eda8n@googlegroups.com> <sr14qt$pg7$1@gioia.aioe.org> <d3b9dc92-4482-4761-9acd-abea342bd8c6n@googlegroups.com>

Show all headers | View raw


On 1/4/22 7:15 PM, Öö Tiib wrote:
> On Tuesday, 4 January 2022 at 11:43:12 UTC+2, Manfred wrote:
>> On 1/4/2022 8:50 AM, Öö Tiib wrote:
>>> On Tuesday, 4 January 2022 at 00:15:10 UTC+2, Manfred wrote:
>>>> On 1/3/2022 9:11 AM, red floyd wrote:
>>>>> On 1/2/2022 10:21 PM, Juha Nieminen wrote:
>>>>>> Manfred <non...@add.invalid> wrote:
>>>>>>> namespace my
>>>>>>> {
>>>>>>> static constexpr float inf = std::numeric_limits<float>::infinity();
>>>>>>> }
>>>>>>
>>>>>> I don't think a constexpr variable needs to be 'static'.
>>>>>
>>>>> Yeah, don't they have internal linkage by default, like const does?
>>>> That's true, but I still like to be explicit, since 'static' and 'const'
>>>> mean different things.
>>>>
>>>> The irony is that this is probably one of those examples where C beats
>>>> C++ - good ol' HUGE_VALF or INFINITE would raise no question at all!
>>>
>>> The std::numeric_limits<float>::infinity() does not raise questions
>>> in actual programs either. It is infinity of float, very explicitly.
>> No, I'm talking about these questions about 'static', 'const',
>> 'constexpr' and similar entertainment. In C INFINITE and HUGE_VAL are
>> "constant expressions", and that is it - good for any purpose.
> 
> Then I'm lost ... std::numeric_limits<float>::infinity() IS constant expression
> and that is it, good for any purpose.

I'll try and lend you a compass:

Manfred wrote:
> And obviously, if you really want it C++ish
> 
> namespace my
> {
>   static constexpr float inf = std::numeric_limits<float>::infinity();
> }
> 
> /* use my::inf wherever you like */

The reason for it was to try and please C++ purists (we're in c.l.c++ 
after all), and get a compact representation of INF - I can see the 
issue with using std::numeric_limits<float>::infinity() embedded in some 
application expression, which serves totally different purposes than 
inspecting the details of numeric representation of the implementation.

So, suppose you want compact, but you don't like <math.h>, the above is 
an answer - note that obviously you want my::inf to be a constant 
expression. Also, you want it local (as you say below), and along 
similar lines I made it 'static', to make it clear - even if 'constexpr' 
defaults to it.

BUT, then people started whirling around the use of 'static' in 
combination with 'const' and 'constexpr' and all that fuzz - again, good 
ol' C wouldn't do that - you'd just use INFINITY or one of the HUGE_VAL 
variants, and be done with it.


> 
>>> Issues of BM with it are pseudo-issues. Too lot of characters?
>>> WTF? Did the hard drive get full? Name some local constant
>>> like "beyond_horizon" or something. Next BM needs to output it to
>>> json as number and then what? Runs away crying?

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

1.0 / 0.0 Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-29 20:00 +0100
  Re: 1.0 / 0.0 Jack Lemmon <invalid@invalid.net> - 2021-12-29 19:15 +0000
    Re: 1.0 / 0.0 Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-29 21:20 +0100
  Re: 1.0 / 0.0 "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-12-29 13:08 -0800
    Re: 1.0 / 0.0 "daniel...@gmail.com" <danielaparker@gmail.com> - 2021-12-29 20:37 -0800
  Re: 1.0 / 0.0 Paavo Helde <eesnimi@osa.pri.ee> - 2021-12-30 17:25 +0200
    Re: 1.0 / 0.0 "daniel...@gmail.com" <danielaparker@gmail.com> - 2021-12-30 08:55 -0800
  Re: 1.0 / 0.0 Manfred <noname@add.invalid> - 2021-12-30 18:48 +0100
    Re: 1.0 / 0.0 "daniel...@gmail.com" <danielaparker@gmail.com> - 2021-12-30 10:16 -0800
      Re: 1.0 / 0.0 Manfred <noname@add.invalid> - 2021-12-30 20:02 +0100
        Re: 1.0 / 0.0 Muttley@dastardlyhq.com - 2021-12-31 10:25 +0000
          Re: 1.0 / 0.0 Manfred <noname@add.invalid> - 2021-12-31 18:34 +0100
            Re: 1.0 / 0.0 Juha Nieminen <nospam@thanks.invalid> - 2022-01-03 06:21 +0000
              Re: 1.0 / 0.0 red floyd <no.spam.here@its.invalid> - 2022-01-03 00:11 -0800
                Re: 1.0 / 0.0 "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-01-03 09:28 +0100
                Re: 1.0 / 0.0 Juha Nieminen <nospam@thanks.invalid> - 2022-01-03 08:36 +0000
                Re: 1.0 / 0.0 Muttley@dastardlyhq.com - 2022-01-03 09:24 +0000
                Re: 1.0 / 0.0 David Brown <david.brown@hesbynett.no> - 2022-01-03 17:14 +0100
                Re: 1.0 / 0.0 Muttley@dastardlyhq.com - 2022-01-03 16:22 +0000
                Re: 1.0 / 0.0 scott@slp53.sl.home (Scott Lurndal) - 2022-01-03 17:40 +0000
                Re: 1.0 / 0.0 Muttley@dastardlyhq.com - 2022-01-04 09:15 +0000
                Re: 1.0 / 0.0 scott@slp53.sl.home (Scott Lurndal) - 2022-01-04 15:24 +0000
                Re: 1.0 / 0.0 Muttley@dastardlyhq.com - 2022-01-04 16:06 +0000
                Re: 1.0 / 0.0 Juha Nieminen <nospam@thanks.invalid> - 2022-01-04 07:58 +0000
                Re: 1.0 / 0.0 Muttley@dastardlyhq.com - 2022-01-04 09:17 +0000
                Re: 1.0 / 0.0 Manfred <noname@add.invalid> - 2022-01-03 23:14 +0100
                Re: 1.0 / 0.0 Öö Tiib <ootiib@hot.ee> - 2022-01-03 23:50 -0800
                Re: 1.0 / 0.0 Manfred <noname@add.invalid> - 2022-01-04 10:42 +0100
                Re: 1.0 / 0.0 Öö Tiib <ootiib@hot.ee> - 2022-01-04 10:15 -0800
                Re: 1.0 / 0.0 Manfred <noname@invalid.add> - 2022-01-04 20:49 +0100
                Re: 1.0 / 0.0 Öö Tiib <ootiib@hot.ee> - 2022-01-04 15:40 -0800
                Re: 1.0 / 0.0 Juha Nieminen <nospam@thanks.invalid> - 2022-01-04 08:34 +0000
                Re: 1.0 / 0.0 Manfred <noname@add.invalid> - 2022-01-04 10:47 +0100
                Re: 1.0 / 0.0 Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-16 12:40 -0800

csiph-web