Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #84180
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: C++ (and some C) quiz questions |
| Date | 2022-05-19 14:43 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <t65l30$1eic$1@gioia.aioe.org> (permalink) |
| References | (6 earlier) <86o7zw2x55.fsf@linuxsc.com> <t61tbu$1dmq$1@gioia.aioe.org> <t62lbd$12vc$1@gioia.aioe.org> <8635h72bap.fsf@linuxsc.com> <t630am$4kh$1@dont-email.me> |
Paavo Helde <eesnimi@osa.pri.ee> wrote: >> That is one possibility, but I didn't mean just that. >> >> Here is the original context: >> >> long double value = 0.1; >> >> I'm not sure what C++ allows or doesn't allow for the value of >> the literal 0.1. >> >> For C, my understanding is that the current C standard allows the >> constant 0.1 to be represented in the format, and precision, of a >> long double even though its type is double. (The rules for >> floating constants in C has changed over time so I'm not sure if >> that allowance might be different for earlier C standards.) >> >> The next C standard apparently will be explicit on this point - >> in the n2731 draft of the C standard, section 6.4.4.2 paragraph 6 >> says this in part: >> >> The values of floating constants may be represented in >> greater range and precision than that required by the type >> (determined by the suffix); the types are not changed >> thereby. > > Doesn't it just mean that in the program code, one can write the literal > with more precision than needed, just in case the type may have more > precision in another or future implementation? > > const double pi = 3.141592653589793238462643383279502884197; There may indeed be a bit of confusion in concepts at play here. After all, there are three stages of compilation at which precision of a floating point literal plays a role: In the ascii representation of the value in the source code, the internal value that the compiler converts that ascii representation to, and the value that ends up in the executable binary. All three may (in a sense, when it comes to the first form) use different precisions. I really think that something like a programming language standard should be clearer and more unambiguous about things like this (unless, perhaps, the standard specifies somewhere else precisely what it means by "values" being "represented".)
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++ (and some C) quiz questions Juha Nieminen <nospam@thanks.invalid> - 2022-05-16 11:21 +0000
Re: C++ (and some C) quiz questions Paavo Helde <eesnimi@osa.pri.ee> - 2022-05-16 17:35 +0300
Re: C++ (and some C) quiz questions Juha Nieminen <nospam@thanks.invalid> - 2022-05-16 16:13 +0000
Re: C++ (and some C) quiz questions Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-05-16 10:49 -0700
Re: C++ (and some C) quiz questions Christian Gollwitzer <auriocus@gmx.de> - 2022-05-16 20:02 +0200
Re: C++ (and some C) quiz questions "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-05-16 20:51 +0200
Re: C++ (and some C) quiz questions Christian Gollwitzer <auriocus@gmx.de> - 2022-05-16 20:59 +0200
Re: C++ (and some C) quiz questions Manfred <noname@add.invalid> - 2022-05-16 21:55 +0200
Re: C++ (and some C) quiz questions Christian Gollwitzer <auriocus@gmx.de> - 2022-05-16 22:09 +0200
Re: C++ (and some C) quiz questions Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-05-16 13:47 -0700
Re: C++ (and some C) quiz questions Ben <ben.usenet@bsb.me.uk> - 2022-05-16 22:19 +0100
Re: C++ (and some C) quiz questions Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-05-16 14:52 -0700
Re: C++ (and some C) quiz questions Ben <ben.usenet@bsb.me.uk> - 2022-05-16 22:57 +0100
Re: C++ (and some C) quiz questions Paavo Helde <eesnimi@osa.pri.ee> - 2022-05-17 00:54 +0300
Re: C++ (and some C) quiz questions Ben <ben.usenet@bsb.me.uk> - 2022-05-17 00:34 +0100
Re: C++ (and some C) quiz questions Christian Gollwitzer <auriocus@gmx.de> - 2022-05-17 08:24 +0200
Re: C++ (and some C) quiz questions Juha Nieminen <nospam@thanks.invalid> - 2022-05-17 08:21 +0000
Re: C++ (and some C) quiz questions Ben <ben.usenet@bsb.me.uk> - 2022-05-17 11:06 +0100
Re: C++ (and some C) quiz questions Juha Nieminen <nospam@thanks.invalid> - 2022-05-17 04:41 +0000
Re: C++ (and some C) quiz questions Ben <ben.usenet@bsb.me.uk> - 2022-05-17 11:12 +0100
Re: C++ (and some C) quiz questions Paavo Helde <eesnimi@osa.pri.ee> - 2022-05-17 14:37 +0300
Re: C++ (and some C) quiz questions Ben <ben.usenet@bsb.me.uk> - 2022-05-17 14:31 +0100
Re: C++ (and some C) quiz questions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-05-17 04:53 -0700
Re: C++ (and some C) quiz questions Juha Nieminen <nospam@thanks.invalid> - 2022-05-18 04:40 +0000
Re: C++ (and some C) quiz questions Manfred <noname@add.invalid> - 2022-05-18 13:29 +0200
Re: C++ (and some C) quiz questions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-05-18 06:57 -0700
Re: C++ (and some C) quiz questions Paavo Helde <eesnimi@osa.pri.ee> - 2022-05-18 17:37 +0300
Re: C++ (and some C) quiz questions Juha Nieminen <nospam@thanks.invalid> - 2022-05-19 14:43 +0000
Re: C++ (and some C) quiz questions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-05-19 08:21 -0700
Re: C++ (and some C) quiz questions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-05-18 06:01 -0700
csiph-web