From owner-freebsd-numerics@FreeBSD.ORG Fri Sep 12 21:15:58 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 284EFE7C for ; Fri, 12 Sep 2014 21:15:58 +0000 (UTC) Received: from mail-yk0-x22d.google.com (mail-yk0-x22d.google.com [IPv6:2607:f8b0:4002:c07::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DCCC0AA7 for ; Fri, 12 Sep 2014 21:15:57 +0000 (UTC) Received: by mail-yk0-f173.google.com with SMTP id 19so749971ykq.18 for ; Fri, 12 Sep 2014 14:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=XRCNJY+dPAKlOTMGGI2H5Vpn/HdzvUkMQS8VVgb5esU=; b=KadNqIgv35EirTotVTL0nNJQy6aeMLsI23GzXGYnw9btvElqAYGW7bkrre1VBQobTL ld6FHn6fcZ3vwZWkFxko80IZGFEkgTYXemCBP+KbLR7764PL+wUWUmHq9J7iD+/0xY5Z E+NSKs/mTUiioiT6KqmsKCv2yl/NwGZfS+uOznw1H1W784Wgmy78iTYDNiQ9UOw/BRGz upSFIXhmOPTkwhE38ZsTuCprzJYgWnW1A0YiTIhukgO86m6UZ6j+OiY93DpmmlsXx90w ctUC15S6AYpvyvp5ktQjarWpK8co9JU5i8xE0rbq60fj9eMPWwBcuW9ZKxog913Zm7bN CmhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=XRCNJY+dPAKlOTMGGI2H5Vpn/HdzvUkMQS8VVgb5esU=; b=b7TQcakSULNcxGgUgGJ24+FRxtBG6s86coF1RpdJ0xjrv5UxaQQnPJphuX5j87QUs3 fDc2H//QCd/OfcSGRTX5evvJ3yIeLjptGM3aV0X6Hh/ljKNrxprQ+tX+Jt2I61zHb7HZ g7JCvlGCaSougv9GpNY/4Dvl2ec8Ua9UyPhaEO1mIybHcRKTWGfHr6fyNfnds1xPl2nS qq+DWIHg7h8mOVD8NTQNpVTK7z5vybvcy5U3KrcqZp7eMEiPbdABeiYlSAF04BEo66h9 6wh30R/K/bFN/X+4CG2TuVSi0V2WhA3Na0Q6jwhSHm/lIjLal9o+Ljg02+IYVRJnj2jk Ku4w== X-Gm-Message-State: ALoCoQnBongM20T5HM7bS+hcNkcWdjKJzfA3i9m/m2+g/1qhbt7q0l0PFxb4NwYWMfOWHKjjhQZs X-Received: by 10.236.71.227 with SMTP id r63mr12882433yhd.2.1410556557104; Fri, 12 Sep 2014 14:15:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.170.147.69 with HTTP; Fri, 12 Sep 2014 14:15:37 -0700 (PDT) From: enh Date: Fri, 12 Sep 2014 14:15:37 -0700 Message-ID: Subject: lgamma_r and lgammaf_r return the wrong sign for -0.f To: freebsd-numerics@freebsd.org Content-Type: text/plain; charset=UTF-8 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 21:15:58 -0000 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. 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. 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.) --elliott (Android libc maintainer) Index: lib/msun/src/e_lgammaf_r.c =================================================================== --- lib/msun/src/e_lgammaf_r.c (revision 271480) +++ lib/msun/src/e_lgammaf_r.c (working copy) @@ -140,7 +140,11 @@ *signgamp = 1; ix = hx&0x7fffffff; if(ix>=0x7f800000) return x*x; - if(ix==0) return one/vzero; + if(ix==0) { + if(hx<0) + *signgamp = -1; + return one/vzero; + } if(ix<0x35000000) { /* |x|<2**-21, return -log(|x|) */ if(hx<0) { *signgamp = -1; Index: lib/msun/src/e_lgamma_r.c =================================================================== --- lib/msun/src/e_lgamma_r.c (revision 271480) +++ lib/msun/src/e_lgamma_r.c (working copy) @@ -212,7 +212,11 @@ *signgamp = 1; ix = hx&0x7fffffff; if(ix>=0x7ff00000) return x*x; - if((ix|lx)==0) return one/vzero; + if((ix|lx)==0) { + if(hx<0) + *signgamp = -1; + return one/vzero; + } if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */ if(hx<0) { *signgamp = -1;