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


Groups > comp.lang.c > #165594

Re: Adjusting printf() rounding

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Adjusting printf() rounding
Date 2022-04-09 09:28 -0700
Organization A noiseless patient Spider
Message-ID <86ilri9q6q.fsf@linuxsc.com> (permalink)
References <t2pag0$eab$1@dont-email.me> <t2pn31$jkc$1@dont-email.me>

Show all headers | 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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