Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #83547
| From | Andrey Tarasevich <andreytarasevich@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Adjusting printf() rounding |
| Date | 2022-04-09 09:10 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <t2sb6d$as9$1@dont-email.me> (permalink) |
| References | <t2pag0$eab$1@dont-email.me> <t2sarf$7g9$1@dont-email.me> |
On 4/9/2022 9:05 AM, Andrey Tarasevich wrote:
> On 4/8/2022 5:40 AM, Paavo Helde wrote:
>>
>> What's worse, it appears MSVC have not kept the promises which they
>> made, and have reverted back to pre-MSVC19 behavior in VS2019 Update
>> 11 (_MSC_VER==1929), rounding ties now up again.
>>
>
> Technically, it is no longer a promise of MSVC, but rather a promise of
> Windows SDK. However, it is run-time controllable through such internal
> SDK options as
>
> _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING
>
> and apparently different versions of MSVC set different initial settings
> in the program's startup code, since the same version of SDK produces
> different results in different versions of MSVC.
>
Also, once you enable
_CRT_INTERNAL_PRINTF_STANDARD_ROUNDING
`printf` in MSVC begins to obey the rounding modes set by `fesetround`
#include <cstdio>
#include <cfenv>
int main()
{
*__local_stdio_printf_options() |=
_CRT_INTERNAL_PRINTF_STANDARD_ROUNDING;
std::printf("%.3g\n", 212.5);
std::fesetround(FE_UPWARD);
std::printf("%.3g\n", 212.5);
std::fesetround(FE_DOWNWARD);
std::printf("%.3g\n", 212.5);
std::fesetround(FE_TONEAREST);
std::printf("%.3g\n", 212.5);
}
212
213
212
212
--
Best regards,
Andrey Tarasevich
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-08 15:40 +0300
Re: Adjusting printf() rounding Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-04-08 06:02 -0700
Re: Adjusting printf() rounding Marcel Mueller <news.5.maazl@spamgourmet.org> - 2022-04-08 18:21 +0200
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-08 19:38 +0300
Re: Adjusting printf() rounding Sams Lara <samlara622@gmail.com> - 2022-04-08 18:48 +0100
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-08 23:44 +0300
Re: Adjusting printf() rounding Marcel Mueller <news.5.maazl@spamgourmet.org> - 2022-04-09 12:58 +0200
Re: Adjusting printf() rounding Geoff <geoff@invalid.invalid> - 2022-04-09 08:45 -0700
Re: Adjusting printf() rounding Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-04-09 13:05 -0700
Re: Adjusting printf() rounding red floyd <no.spam.here@its.invalid> - 2022-04-09 13:36 -0700
Re: Adjusting printf() rounding Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-09 16:08 -0700
Re: Adjusting printf() rounding Manfred <noname@add.invalid> - 2022-04-08 21:30 +0200
Re: Adjusting printf() rounding "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-04-09 10:11 +0200
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-10 16:39 +0300
Re: Adjusting printf() rounding Sams Lara <samlara622@gmail.com> - 2022-04-10 18:36 +0100
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-10 21:50 +0300
Re: Adjusting printf() rounding Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-09 09:05 -0700
Re: Adjusting printf() rounding Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-09 09:10 -0700
csiph-web