Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Mar 1995 21:20:02 -0800
From:      Mark Diekhans <markd@grizzly.com>
To:        freebsd-bugs
Subject:   misc/272: Broken printf floating point formatting
Message-ID:  <199503240520.VAA14745@freefall.cdrom.com>
In-Reply-To: Your message of Thu, 23 Mar 1995 20:47:31 -0800 <199503240447.UAA01545@Grizzly.COM>

index | next in thread | previous in thread | raw e-mail


>Number:         272
>Category:       misc
>Synopsis:       Broken printf floating point formatting
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs (FreeBSD bugs mailing list)
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 23 21:20:01 1995
>Originator:     Mark Diekhans
>Organization:
== Mark Diekhans (markd@grizzly.com)     ==
>Release:        FreeBSD 2.0-RELEASE i386
>Environment:

>Description:

printf ("%e", 3.42e12);  outputs "3.42e+12", it should output  "3.420000e+12".

printf ("%#.0f", 0.0);  outputs "0", it should output  "0.".

printf ("%#.0g", 0.0);  outputs "0.e+00", it should output  "0.".


These results conflict with the printf (3) manual page and the behavior
on other systems (I tried SunOS, HP-UX and SCO).


>How-To-Repeat:

#include <stdio.h>

void
Out (format, valueStr, value)
    char   *format;
    char   *valueStr;
    double  value;
{
    char spec [1024];

    strcpy (spec, "%s of %s = ");
    strcat (spec, format);
    strcat (spec, "\n");

    printf (spec, format, valueStr, value);
}

int
main ()
{
    Out ("%e", "3.42e12", 3.42e12);
    Out ("%.4e", "-9.99996", -9.99996);
    Out ("%#.0f", "0.0", 0.0);
    Out ("%#.0g", "0.0", 0.0);
    return 0;
}

>Fix:
	


>Audit-Trail:
>Unformatted:




help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199503240520.VAA14745>