From owner-freebsd-numerics@FreeBSD.ORG Fri Sep 12 22:05:45 2014 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3BC52CDD for ; Fri, 12 Sep 2014 22:05:45 +0000 (UTC) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "troutmask.apl.washington.edu", Issuer "troutmask.apl.washington.edu" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 19006FEB for ; Fri, 12 Sep 2014 22:05:45 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.9/8.14.9) with ESMTP id s8CM5im0097520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 12 Sep 2014 15:05:44 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.9/8.14.9/Submit) id s8CM5i6d097519; Fri, 12 Sep 2014 15:05:44 -0700 (PDT) (envelope-from sgk) Date: Fri, 12 Sep 2014 15:05:44 -0700 From: Steve Kargl To: enh Subject: Re: lgamma_r and lgammaf_r return the wrong sign for -0.f Message-ID: <20140912220544.GA96714@troutmask.apl.washington.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Cc: freebsd-numerics@freebsd.org X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Sep 2014 22:05:45 -0000 On Fri, Sep 12, 2014 at 02:15:37PM -0700, enh via freebsd-numerics wrote: > if I pass -0.f to lgammaf_r, the sign returned in *signgamp is 1. this > is incorrect --- it should be -1. > > both lgamma_r and lgammaf_r are affected, but the other special cases > in those functions look fine to me. > > this is fixed in OpenBSD and glibc, but FreeBSD and NetBSD both have > the same bug. Are you sure FreeBSD has a bug? From n1256.pdf (committee draft of C99) F.9.5.3 The lgamma functions -- lgamma(1) returns +0. -- lgamma(2) returns +0. -- lgamma(x) returns +inf and raises the ``divide-by-zero'' floating-pointr exception for x a negative integer or zero. -- lgamma(-inf) returns +inf. -- lgamma(+inf) returns +inf. See the 3rd bullet. -0 is 0 and -0 is a negative integer. POSIX appears to defer to ISO C. n1570.pdf (committe draft for C11) has (almost?) identical text. > patch below (whitespace mangled courtesy of gmail). i'd prefer to wait > for this to be fixed in FreeBSD and pull down the fix rather than just > fix it locally. I have a bigger patch coming with ld80 and ld128 version of lgammal and lgammal_r. > btw, it looks like you're missing coshl/sinhl/tanhl for ld128 now? > (they've been removed from imprecise.c without having ld128 > implementations added afaics.) The ld80 and ld128 versions are in the same file. troutmask:fvwm:kargl[226] grep LDBL /usr/src/lib/msun/src/e_coshl.c #if LDBL_MAX_EXP != 0x4000 #define BIAS (LDBL_MAX_EXP - 1) #if LDBL_MANT_DIG == 64 #elif LDBL_MANT_DIG == 113 #endif /* LDBL_MANT_DIG == 64 */ GET_LDBL_EXPSIGN(ix,x); if (ix