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

            Bug ID: 94654
           Summary: printf calls with floats
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tydeman at tybor dot com
  Target Milestone: ---

/*
 * These should all print the same thing:  2e+35
 */
#include <stdio.h>

#define FMT  "%.14g"
#define FMTL "%.14Lg"

int main(void){
  const long double ld = 2e+35L;
  const double       d = 2e+35;
  const float        f = 2e+35F;

  (void)printf("1:" FMT  "\n", f );
  (void)printf("2:" FMT  "\n", (double)f );
  (void)printf("3:" FMT  "\n", 2e+35F );
  (void)printf("4:" FMT  "\n", (double)2e+35F );
  (void)printf("5:" FMT  "\n", (float)d );
  (void)printf("6:" FMT  "\n", (float)ld );

  (void)printf("a:" FMT  "\n", d );
  (void)printf("b:" FMT  "\n", 2e+35 );
  (void)printf("c:" FMTL "\n", ld );
  (void)printf("d:" FMTL "\n", 2e+35L );

  return 0;
}

The first 6 print as if %f (which is wrong).
The last 4 print as if %e
varargs are supposed to promote float to double.

Reply via email to