Subject: lib/6314: Bug in libc with `double' => `long long' conversions
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tege@matematik.su.se>
List: netbsd-bugs
Date: 10/17/1998 19:53:16
>Number:         6314
>Category:       lib
>Synopsis:       Conversion result `double' => `long long' off by one
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 17 11:05:01 1998
>Last-Modified:
>Originator:     Torbjorn Granlund
>Organization:
TMG Datakonsult
>Release:        NetBSD-current snapshot from 980808
>Environment:
	Apple Powermac 9600 (604e @ 350MHz)
System: NetBSD haj.tmg.se 1.3G NetBSD 1.3G (GENERIC) #0: Mon Aug 10 16:46:26 JST 1998 tsubai@kanea:/c/0808/src/sys/arch/macppc/compile/GENERIC macppc

>Description:
Result of conversions from `double' to `long long' sometimes give a result
that is too big.  This is *not* the result of the inexact nature of
floating-point.  The incorrect result is generated when the floating-point
value is an integer that need not be rounded when it is assigned to a `long
long'.
>How-To-Repeat:
Compile the following program and execute it.  It will print 280379776630786
instead of 280379776630785 as it should.  The bug seems to affect several
NetBSD platforms.  It also happens on i386 and mac68k.

long long f (double x) { return x; }
main () { printf ("%qd\n", f (280379776630785.0)); }
>Fix:

>Audit-Trail:
>Unformatted: