>From FreeBSD 23397: 
Fixed wrong magic numbers in scaling.  hypotf() was very broken for large
and small values:

    hypotf(2.3819765e+38, 2.0416943e+38) was NaN instead of 3.1372484e+38
    hypotf(-3.4028235e+38, 3.3886450e+38) was NaN instead of Inf
    hypotf(-2.8025969e-45, -2.8025969e-45) was 0 instead of 4.2038954e-45

Found by:   ucbtest

Comment ? OK ?

-- 
Alexandr Shadchin

Index: e_hypotf.c
===================================================================
RCS file: /cvs/src/lib/libm/src/e_hypotf.c,v
retrieving revision 1.5
diff -u -p -r1.5 e_hypotf.c
--- e_hypotf.c  27 Oct 2009 23:59:29 -0000      1.5
+++ e_hypotf.c  4 Nov 2015 21:44:01 -0000
@@ -38,22 +38,22 @@ hypotf(float x, float y)
               if(hb == 0x7f800000) w = b;
               return w;
           }
-          /* scale a and b by 2**-60 */
-          ha -= 0x5d800000; hb -= 0x5d800000;  k += 60;
+          /* scale a and b by 2**-68 */
+          ha -= 0x22000000; hb -= 0x22000000;  k += 68;
           SET_FLOAT_WORD(a,ha);
           SET_FLOAT_WORD(b,hb);
        }
        if(hb < 0x26800000) {   /* b < 2**-50 */
            if(hb <= 0x007fffff) {      /* subnormal b or 0 */  
                if(hb==0) return a;
-               SET_FLOAT_WORD(t1,0x3f000000);  /* t1=2^126 */
+               SET_FLOAT_WORD(t1,0x7e800000);  /* t1=2^126 */
                b *= t1;
                a *= t1;
                k -= 126;
-           } else {            /* scale a and b by 2^60 */
-               ha += 0x5d800000;       /* a *= 2^60 */
-               hb += 0x5d800000;       /* b *= 2^60 */
-               k -= 60;
+           } else {            /* scale a and b by 2^68 */
+               ha += 0x22000000;       /* a *= 2^68 */
+               hb += 0x22000000;       /* b *= 2^68 */
+               k -= 68;
                SET_FLOAT_WORD(a,ha);
                SET_FLOAT_WORD(b,hb);
            }

Reply via email to