math: simplify hypot and hypotf using scalbn
this also fixes overflow/underflow raising and excess precision issues (as those are handled well in scalbn)
This commit is contained in:
parent
6d3f1a39c1
commit
529a8de46c
2 changed files with 4 additions and 11 deletions
|
|
@ -117,12 +117,7 @@ double hypot(double x, double y)
|
||||||
t2 = a - t1;
|
t2 = a - t1;
|
||||||
w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
|
w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
|
||||||
}
|
}
|
||||||
if (k != 0) {
|
if (k)
|
||||||
uint32_t high;
|
w = scalbn(w, k);
|
||||||
t1 = 1.0;
|
|
||||||
GET_HIGH_WORD(high, t1);
|
|
||||||
SET_HIGH_WORD(t1, high+(k<<20));
|
|
||||||
return t1*w;
|
|
||||||
}
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,7 @@ float hypotf(float x, float y)
|
||||||
t2 = a - t1;
|
t2 = a - t1;
|
||||||
w = sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
|
w = sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
|
||||||
}
|
}
|
||||||
if (k != 0) {
|
if (k)
|
||||||
SET_FLOAT_WORD(t1, 0x3f800000+(k<<23));
|
w = scalbnf(w, k);
|
||||||
return t1*w;
|
|
||||||
}
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue