Date: Tue, 3 Feb 2015 08:33:29 -0800 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: Bruce Evans <brde@optusnet.com.au> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, "Pedro F. Giffuni" <pfg@freebsd.org>, src-committers@freebsd.org Subject: Re: svn commit: r278154 - head/lib/msun/src Message-ID: <20150203163329.GA12706@troutmask.apl.washington.edu> In-Reply-To: <20150204012614.T1972@besplex.bde.org> References: <201502031417.t13EHU9g074687@svn.freebsd.org> <20150204012614.T1972@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <limits.h> +#include <float.h> #include <math.h> +#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)); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150203163329.GA12706>