www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/07/00:54:37

Date: Mon, 6 Feb 95 20:10 MST
From: mat AT ardi DOT com (Mat Hostetter)
To: haltmaye AT mathpool DOT uni-augsburg DOT de
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu, gnewman AT world DOT std DOT com
Subject: Re: DJGPP Floating Point Problem
References: <9502070101 DOT AA29653 AT aixcip02 DOT Math DOT Uni-Augsburg DOT DE>

>>>>> "haltmaye" == haltmaye  <haltmaye AT mathpool DOT uni-augsburg DOT de> writes:

    haltmaye> Format %f in printf expects a float while 100.0 is a
    haltmaye> double number.  Try %lf or %g.

Wrong!  This is a classic C error.  Under ANSI C, "%lf" is invalid as
a printf specifier, although many printf implementations accept it.
printf doesn't need a separate %lf because floats are promoted to
doubles.  If you don't believe me, try compiling this small test
program using "gcc -Wall":

#include <stdio.h>

void
foo ()
{
  printf ("%lf\n", 1.0);
}

gwar:~$ gcc -Wall -c foo.c
foo.c: In function `foo':
foo.c:6: warning: use of `l' length character with `f' type character

-Mat

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019