From owner-svn-src-head@FreeBSD.ORG Tue Feb 3 16:33:31 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BBAFC79F; Tue, 3 Feb 2015 16:33:31 +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", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 92493845; Tue, 3 Feb 2015 16:33:31 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.14.9/8.14.9) with ESMTP id t13GXTsh012986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 3 Feb 2015 08:33:30 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.9/8.14.9/Submit) id t13GXTr5012985; Tue, 3 Feb 2015 08:33:29 -0800 (PST) (envelope-from sgk) Date: Tue, 3 Feb 2015 08:33:29 -0800 From: Steve Kargl To: Bruce Evans Subject: Re: svn commit: r278154 - head/lib/msun/src Message-ID: <20150203163329.GA12706@troutmask.apl.washington.edu> References: <201502031417.t13EHU9g074687@svn.freebsd.org> <20150204012614.T1972@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150204012614.T1972@besplex.bde.org> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, "Pedro F. Giffuni" , src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Feb 2015 16:33:32 -0000 On Wed, Feb 04, 2015 at 02:38:40AM +1100, Bruce Evans wrote: > On Tue, 3 Feb 2015, Pedro F. Giffuni wrote: > > > Log: > > Reduce confusion in scalbnl() family of functions. > > > > The changes unrelated to the bug in r277948 made > > the code very difficult to understand to both > > coverity and regular humans so take a step back > > to something that is much easier to understand > > for both and follows better the original code. > > > > CID: 1267992, 1267993, 1267994 > > Discussed with: kargl > > You mean, take a step backwards to something that is harder to understand. > Well, the correct fix should have been to ONLY fix the typo, and leave the code rewrite for a second commit. Index: s_scalbln.c =================================================================== --- s_scalbln.c (revision 276768) +++ s_scalbln.c (working copy) @@ -72,5 +72,5 @@ else in = INT_MIN; } - return (scalbnl(x, (int)n)); + return (scalbnl(x, in)); } But, that's water under the bridge. You forgot to include a diff. Here's one untested attempt at addressing your concerns. -- Steve Index: s_scalbln.c =================================================================== --- s_scalbln.c (revision 276768) +++ s_scalbln.c (working copy) @@ -27,21 +27,23 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include +#define FLT_LARGE FLT_MAX_EXP - FLT_MIN_EXP + FLT_MANT_DIG +#define FLT_SMALL FLT_MIN_EXP - FLT_MAX_EXP +#define DBL_LARGE DBL_MAX_EXP - DBL_MIN_EXP + DBL_MANT_DIG +#define DBL_SMALL DBL_MIN_EXP - DBL_MAX_EXP +#define LDBL_LARGE LDBL_MAX_EXP - LDBL_MIN_EXP + LDBL_MANT_DIG +#define LDBL_SMALL LDBL_MIN_EXP - LDBL_MAX_EXP + double scalbln (double x, long n) { int in; - in = (int)n; - if (in != n) { - if (n > 0) - in = INT_MAX; - else - in = INT_MIN; - } + in = n > DBL_LARGE ? DBL_LARGE : n < DBL_SMALL ? DBL_SMALL : n; + return (scalbn(x, in)); } @@ -50,27 +52,16 @@ { int in; - in = (int)n; - if (in != n) { - if (n > 0) - in = INT_MAX; - else - in = INT_MIN; - } + in = n > FLT_LARGE ? FLT_LARGE : n < FLT_SMALL ? FLT_SMALL : n; + return (scalbnf(x, in)); } - long double scalblnl (long double x, long n) { int in; - in = (int)n; - if (in != n) { - if (n > 0) - in = INT_MAX; - else - in = INT_MIN; - } - return (scalbnl(x, (int)n)); + in = n > LDBL_LARGE ? LDBL_LARGE : n < LDBL_SMALL ? LDBL_SMALL : n; + + return (scalbnl(x, in)); }