public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102498] New: wrong output of printf with long double constant and non-default rounding mode
@ 2021-09-27 14:27 zimmerma+gcc at loria dot fr
  2021-09-27 15:00 ` [Bug c/102498] wrong output of printf with long double constant (pi) " vincent-gcc at vinc17 dot net
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: zimmerma+gcc at loria dot fr @ 2021-09-27 14:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102498

            Bug ID: 102498
           Summary: wrong output of printf with long double constant and
                    non-default rounding mode
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zimmerma+gcc at loria dot fr
  Target Milestone: ---

with the following program:

#include <stdio.h>
#include <math.h>
#include <fenv.h>
const long double a = 0xc.90fdaa22168c235p-1l;
const long double b = 0xc.90fdaa22168c235p-2l;
int main()
{
  fesetround (FE_TONEAREST);
  printf ("FE_TONEAREST:  a=%La b=%La\n", a, b);
  fesetround (FE_TOWARDZERO);
  printf ("FE_TOWARDZERO: a=%La b=%La\n", a, b);
  fesetround (FE_UPWARD);
  printf ("FE_UPWARD:     a=%La b=%La\n", a, b);
  fesetround (FE_DOWNWARD);
  printf ("FE_DOWNWARD:   a=%La b=%La\n", a, b);
}

I get:

$ gcc -frounding-math -O0 -fno-builtin e.c -lm
$ ./a.out 
FE_TONEAREST:  a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c235p-2
FE_TOWARDZERO: a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c234p-2
FE_UPWARD:     a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c235p-2
FE_DOWNWARD:   a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c234p-2

The value 'a' is printed the same whatever the rounding mode, but 'b' (which
approximates pi to nearest) is wrongly printed for FE_TOWARDZERO and
FE_DOWNWARD.

According to Alexander Monakov, the same problem should happen with og_2 10,
log_2 e, log_10 2, and log_e 2, see
https://sourceware.org/pipermail/libc-alpha/2021-September/131411.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-05-11  6:36 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 14:27 [Bug c/102498] New: wrong output of printf with long double constant and non-default rounding mode zimmerma+gcc at loria dot fr
2021-09-27 15:00 ` [Bug c/102498] wrong output of printf with long double constant (pi) " vincent-gcc at vinc17 dot net
2021-09-27 15:11 ` [Bug target/102498] " jakub at gcc dot gnu.org
2021-09-27 15:20 ` jakub at gcc dot gnu.org
2021-09-27 16:50 ` vincent-gcc at vinc17 dot net
2021-09-27 22:35 ` [Bug target/102498] [9/10/11/12 Regression] Long double constant and non-default rounding mode on x86 pinskia at gcc dot gnu.org
2021-09-28  0:57 ` vincent-gcc at vinc17 dot net
2021-09-28  1:14 ` pinskia at gcc dot gnu.org
2021-09-28  8:17 ` vincent-gcc at vinc17 dot net
2021-09-28 11:03 ` cvs-commit at gcc dot gnu.org
2021-09-28 11:07 ` cvs-commit at gcc dot gnu.org
2021-09-28 11:10 ` [Bug target/102498] [9/10 " jakub at gcc dot gnu.org
2022-05-10  8:20 ` cvs-commit at gcc dot gnu.org
2022-05-10  8:46 ` zimmerma+gcc at loria dot fr
2022-05-10 11:57 ` vincent-gcc at vinc17 dot net
2022-05-10 12:00 ` vincent-gcc at vinc17 dot net
2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:36 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).