amath
1.8.5
Simple command line calculator
|
#include "prim.h"
Go to the source code of this file.
Functions | |
double | hypot (double x, double y) |
hypot More... | |
double hypot | ( | double | x, |
double | y | ||
) |
hypot
Method If (assume round-to-nearest) z=x*x+y*y has error less than sqrt(2)/2 ulp, than sqrt(z) has error less than 1 ulp (exercise).
So, compute sqrt(x*x+y*y) with some care as follows to get the error below 1 ulp:
Assume x>y>0; (if possible, set rounding to round-to-nearest) 1. if x > 2y use x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y where x1 = x with lower 32 bits cleared, x2 = x-x1; else 2. if x <= 2y use t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, y1= y with lower 32 bits chopped, y2 = y-y1.
NOTE: scaling may be necessary if some argument is too large or too tiny
Special cases: hypot(x,y) is INF if x or y is +INF or -INF; else hypot(x,y) is NAN if x or y is NAN.
Accuracy: hypot(x,y) returns sqrt(x^2+y^2) with error less than 1 ulps (units in the last place)
Definition at line 81 of file hypot.c.
References sqrt().
Referenced by cabs().