mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Further refine hypot implementation
Thanks go to Fabian Giesen on Twitter for code review and advice.
This commit is contained in:
parent
4a5698b5c9
commit
c6c9b5dfde
4 changed files with 66 additions and 18 deletions
|
@ -22,10 +22,13 @@
|
|||
* Returns euclidean distance.
|
||||
*/
|
||||
double hypot(double a, double b) {
|
||||
double r;
|
||||
double r, t;
|
||||
if (isinf(a) || isinf(b)) return INFINITY;
|
||||
if (isunordered(a, b)) return NAN;
|
||||
if (!a) return 0;
|
||||
a = fabs(a);
|
||||
b = fabs(b);
|
||||
if (a < b) t = b, b = a, a = t;
|
||||
if (!a) return b;
|
||||
r = b / a;
|
||||
return fabs(a) * sqrt(1 + r * r);
|
||||
return a * sqrt(1 + r * r);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue