Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #165594
| Path | csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: Adjusting printf() rounding |
| Date | Sat, 09 Apr 2022 09:28:29 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 36 |
| Message-ID | <86ilri9q6q.fsf@linuxsc.com> (permalink) |
| References | <t2pag0$eab$1@dont-email.me> <t2pn31$jkc$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | reader02.eternal-september.org; posting-host="b8e2dcfc2935dcfe9151ae6ef6f0e059"; logging-data="10326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18B8yxg8goTeaWMa8OhvgB/X76F0oGbuSY=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:8devfT3pih4HhYThJK07/tybsJY= sha1:fypu+PoC+V2n046f5ruplE20n5A= |
| Xref | csiph.com comp.lang.c:165594 |
Show key headers only | View raw
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 4/8/22 08:40, Paavo Helde wrote:
>
>> To be honest, this is a bit off-topic for C++, but maybe you guys
>> have some insight here.
>>
>> [.. behavior of rounding on floating-point output ..]
>>
>> A demo program:
>>
>> $ cat test6.cpp
>> #include <cstdio>
>> int main() {
>> std::printf("%.3g\n", 212.5);
>> }
>> $ g++ test6.cpp
>> $ ./a.out
>> 212
>
> I know nothing MSVC-specific, but I can tell you what the C
> standard requires:
>
> When printing floating point numbers, the *printf*() family is
> supposed to obey the current rounding direction.
> [.. discussion of rounding modes and how to set them ..]
I believe this assertion is an overstatement. Although there are
certain cases where the C standard does mandate correct rounding
(which implies using the current rounding direction), AFAICT
there is no general requirement that all *printf() floating-point
conversions be correctly rounded, or that they obey the current
rounding direction. Note that some statements are made about
rounding (both correct rounding and current rounding direction)
under a "Recommended practice" heading, but these statements are
only recommendations, not requirements.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Adjusting printf() rounding James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-04-08 12:15 -0400
Re: Adjusting printf() rounding Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-04-09 09:28 -0700
Re: Adjusting printf() rounding "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2022-04-09 20:51 -0700
csiph-web