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));
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to