math: simplify hypot and hypotf using scalbn
authorSzabolcs Nagy <nsz@port70.net>
Tue, 13 Nov 2012 20:54:32 +0000 (21:54 +0100)
committerSzabolcs Nagy <nsz@port70.net>
Tue, 13 Nov 2012 20:54:32 +0000 (21:54 +0100)
this also fixes overflow/underflow raising and excess
precision issues (as those are handled well in scalbn)

src/math/hypot.c
src/math/hypotf.c

index ba4c757502a7de95f312047b6823875ea52943c0..9a4cbdb3e25d9fdaa02a6615ffb7b21b2b8433e6 100644 (file)
@@ -117,12 +117,7 @@ double hypot(double x, double y)
                t2 = a - t1;
                w  = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
        }
-       if (k != 0) {
-               uint32_t high;
-               t1 = 1.0;
-               GET_HIGH_WORD(high, t1);
-               SET_HIGH_WORD(t1, high+(k<<20));
-               return t1*w;
-       }
+       if (k)
+               w = scalbn(w, k);
        return w;
 }
index 9fd77e6aa09cfd4db86f1c3c6aa177d52a43f7f2..4d80178de11216c0efa515be57f3ba515c7b9294 100644 (file)
@@ -80,9 +80,7 @@ float hypotf(float x, float y)
                t2 = a - t1;
                w  = sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
        }
-       if (k != 0) {
-               SET_FLOAT_WORD(t1, 0x3f800000+(k<<23));
-               return t1*w;
-       }
+       if (k)
+               w = scalbnf(w, k);
        return w;
 }