From owner-freebsd-sparc64@FreeBSD.ORG Sat Dec 23 14:50:18 2006 Return-Path: X-Original-To: freebsd-sparc64@hub.freebsd.org Delivered-To: freebsd-sparc64@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0687116A412 for ; Sat, 23 Dec 2006 14:50:18 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id A767413C448 for ; Sat, 23 Dec 2006 14:50:17 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id kBNEoHhZ070171 for ; Sat, 23 Dec 2006 14:50:17 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id kBNEoHeO070170; Sat, 23 Dec 2006 14:50:17 GMT (envelope-from gnats) Date: Sat, 23 Dec 2006 14:50:17 GMT Message-Id: <200612231450.kBNEoHeO070170@freefall.freebsd.org> To: freebsd-sparc64@FreeBSD.org From: Marius Strobl Cc: Subject: Re: sparc64/107130: conversion from long double to long giving incorrect values X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Marius Strobl List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Dec 2006 14:50:18 -0000 The following reply was made to PR sparc64/107130; it has been noted by GNATS. From: Marius Strobl To: Jim White Cc: freebsd-gnats-submit@freebsd.org Subject: Re: sparc64/107130: conversion from long double to long giving incorrect values Date: Sat, 23 Dec 2006 15:28:54 +0100 On Sat, Dec 23, 2006 at 07:54:11AM +0000, Jim White wrote: > > >How-To-Repeat: > #include > int main() > { > long double i; > for (i=0;;i=i-1.0) > printf("%Lf %d %ld %lld %f\n",i,(int)i,(long)i,(long long)i,(double)i); > return 0; > } > > Sample Output: > 0.000000 0 0 0 0.000000 > -1.000000 -1 -1 -1 -1.000000 > -2.000000 -2 -1 -1 -2.000000 > -3.000000 -3 -1 -1 -3.000000 > -4.000000 -4 -1 -1 -4.000000 > -5.000000 -5 -1 -1 -5.000000 > -6.000000 -6 -1 -1 -6.000000 > -7.000000 -7 -1 -1 -7.000000 > -8.000000 -8 -1 -1 -8.000000 > -9.000000 -9 -1 -1 -9.000000 > -10.000000 -10 -1 -1 -10.000000 > This appears to be caused by a typo in the FPU emulation code. Could you please give the patch below a try (after applying re-compile and re-install libc, if you're linking your application statically re-compile it afterwards, too)? Marius Index: fpu_implode.c =================================================================== RCS file: /usr/data/bsd/cvs/fbsd/src/lib/libc/sparc64/fpu/fpu_implode.c,v retrieving revision 1.6 diff -u -r1.6 fpu_implode.c --- fpu_implode.c 28 Jul 2004 05:41:05 -0000 1.6 +++ fpu_implode.c 23 Dec 2006 14:20:13 -0000 @@ -277,7 +277,7 @@ if (i >= ((u_int64_t)0x8000000000000000LL + sign)) break; if (sign) - i = -1; + i = -i; res[1] = (int)i; return (i >> 32);