From owner-freebsd-i386@FreeBSD.ORG Thu Aug 18 10:10:25 2005 Return-Path: X-Original-To: freebsd-i386@hub.freebsd.org Delivered-To: freebsd-i386@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5BB0A16A41F for ; Thu, 18 Aug 2005 10:10:25 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C516B43D55 for ; Thu, 18 Aug 2005 10:10:24 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j7IAAOFM087549 for ; Thu, 18 Aug 2005 10:10:24 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j7IAAOi0087546; Thu, 18 Aug 2005 10:10:24 GMT (envelope-from gnats) Resent-Date: Thu, 18 Aug 2005 10:10:24 GMT Resent-Message-Id: <200508181010.j7IAAOi0087546@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-i386@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Vincent Lefevre Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 75E8116A41F for ; Thu, 18 Aug 2005 10:10:12 +0000 (GMT) (envelope-from vincent@vinc17.org) Received: from dixsept.loria.fr (dixsept.loria.fr [152.81.9.195]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2252943D48 for ; Thu, 18 Aug 2005 10:10:11 +0000 (GMT) (envelope-from vincent@vinc17.org) Received: from vlefevre by dixsept.loria.fr with local (Exim 4.52) id 1E5hLe-0004h3-Fz; Thu, 18 Aug 2005 12:10:10 +0200 Message-Id: <20050818101010.GA18024@dixsept.loria.fr> Date: Thu, 18 Aug 2005 12:10:10 +0200 From: Vincent Lefevre To: FreeBSD-gnats-submit@FreeBSD.org Cc: vincent@vinc17.org Subject: i386/85080: output of long double subnormals (with printf) is wrong by a factor 2 X-BeenThere: freebsd-i386@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Vincent Lefevre List-Id: I386-specific issues for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2005 10:10:25 -0000 >Number: 85080 >Category: i386 >Synopsis: output of long double subnormals (with printf) is wrong by a factor 2 >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-i386 >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 18 10:10:24 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Vincent Lefevre >Release: FreeBSD 5.4-RELEASE i386 >Organization: LORIA / INRIA Lorraine >Environment: System: FreeBSD spe152.testdrive.hp.com 5.4-RELEASE FreeBSD 5.4-RELEASE #0: Sun May 8 10:21:06 UTC 2005 root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >Description: When I print the value of a long double with printf ("%Le", x) and the value is a subnormal, I get the value divided by 2. >How-To-Repeat: Consider the following code: #include #include int main (void) { long double x, y; int i; for (x = LDBL_MIN; x != 0; x /= 2.0) { y = x; for (i = 0; i < 10; i++) printf ("%c%02X", i ? ' ' : '[', ((unsigned char *) &y)[i]); printf ("] %.30Le\n", x); } return 0; } I get: [00 00 00 00 00 00 00 80 01 00] 3.362103143112093506262677817322e-4932 [00 00 00 00 00 00 00 40 00 00] 8.405257857780233765656694543304e-4933 [00 00 00 00 00 00 00 20 00 00] 4.202628928890116882828347271652e-4933 [00 00 00 00 00 00 00 10 00 00] 2.101314464445058441414173635826e-4933 The first value is the smallest normalized long double (LDBL_MIN). The decimal output is correct. The decimal output of the following ones is twice lower the correct value. >Fix: I haven't looked at the source, but it seems that the programmer forgot that there is not implicit bit for the extended precision, so that the exponent field is decreased by 1 *and* the mantissa is divided by 2 when going from LDBL_MIN to LDBL_MIN/2 (see above), hence the factor 2. The fix should be simple: add (or subtract) 1 to the bias. >Release-Note: >Audit-Trail: >Unformatted: