1 #include <math.h> 2 #include <stdint.h> 3 hypotf(float x,float y)4float hypotf(float x, float y) 5 { 6 union {float f; uint32_t i;} ux = {x}, uy = {y}, ut; 7 float_t z; 8 9 ux.i &= -1U>>1; 10 uy.i &= -1U>>1; 11 if (ux.i < uy.i) { 12 ut = ux; 13 ux = uy; 14 uy = ut; 15 } 16 17 x = ux.f; 18 y = uy.f; 19 if (uy.i == 0xff<<23) 20 return y; 21 if (ux.i >= 0xff<<23 || uy.i == 0 || ux.i - uy.i >= 25<<23) 22 return x + y; 23 24 z = 1; 25 if (ux.i >= (0x7f+60)<<23) { 26 z = 0x1p90f; 27 x *= 0x1p-90f; 28 y *= 0x1p-90f; 29 } else if (uy.i < (0x7f-60)<<23) { 30 z = 0x1p-90f; 31 x *= 0x1p90f; 32 y *= 0x1p90f; 33 } 34 return z*sqrtf((double)x*x + (double)y*y); 35 } 36