From owner-freebsd-standards@FreeBSD.ORG Sat May 8 15:58:49 2004 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DD02B16A4CE for ; Sat, 8 May 2004 15:58:49 -0700 (PDT) Received: from VARK.homeunix.com (adsl-68-124-137-57.dsl.pltn13.pacbell.net [68.124.137.57]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5151443D4C for ; Sat, 8 May 2004 15:58:49 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Received: from VARK.homeunix.com (localhost [127.0.0.1]) by VARK.homeunix.com (8.12.10/8.12.10) with ESMTP id i48MwcAd016023 for ; Sat, 8 May 2004 15:58:38 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.homeunix.com (8.12.10/8.12.10/Submit) id i48Mwcj6016022 for freebsd-standards@FreeBSD.org; Sat, 8 May 2004 15:58:38 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Date: Sat, 8 May 2004 15:58:38 -0700 From: David Schultz To: freebsd-standards@FreeBSD.ORG Message-ID: <20040508225838.GA15663@VARK.homeunix.com> Mail-Followup-To: freebsd-standards@FreeBSD.org References: <20040508194748.GN29712@wombat.fafoe.narf.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040508194748.GN29712@wombat.fafoe.narf.at> Subject: Re: Fixing ilogb() X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 May 2004 22:58:50 -0000 On Sat, May 08, 2004, Stefan Farfeleder wrote: > I found two problems with our current ilogb() implemenation(s). > > - Both the man page and FP_ILOGB0 claim that ilogb(0) returns INT_MIN > while the implementation in s_ilogb.c returns -INT_MAX. We really > have to decide on one value (both are conforming to C99, I've attached > the text). The attached patch assumes that -INT_MAX is kept. FWIW, SunOS has historically used the following mapping: ilogb(0) ==> -INT_MAX ilogb(NAN) ==> INT_MAX ilogb(INFINITY) ==> INT_MAX This matches OS X, our MI ilogb() implementation[1], and your patch, and I think those are pretty good reasons to use your version. > On a related note, is there a reason why doesn't use > 's __INT_M{AX,IN} for the FP_ILOGB* macros? Yes, machine/_limits.h did not exist when it was written, so there was no way to get INT_{MIN,MAX} without namespace pollution. It would be a good idea to use these in math.h and s_ilogb[f].c now. > - On i386 the assembler file s_ilogb.S is used instead. It uses the > instruction fxtract which returns INT_MIN for 0, infinity and NaN. > Except for infinity this conforms too, but doesn't play well with our > MI definitions for FP_ILOGB*. In the attached patch I've aligned > s_ilogb.S's behaviour with s_ilogb.c, the alternative would be just > fixing infinity and making FP_ILOGB* MD. Although it would be legitimate to make FP_ILOGB* MD, we have to fix the infinity case anyway, so we might as well make the NAN and 0 cases MI. FWIW, I was working on some faster MD implementations of fpclassify() and friends a while ago, and getting these corner cases to be consistent is a big PITA. ;-) [1] This is unsurprising, given its origin.