1 /* Pythagorean addition using doubles
2 Copyright (C) 2011 Free Software Foundation, Inc.
3 This file is part of the GNU C Library
4 Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "math_private.h"
24 static const double two60
= 1.152921504606847e+18;
25 static const double two500
= 3.2733906078961419e+150;
26 static const double two600
= 4.149515568880993e+180;
27 static const double two1022
= 4.49423283715579e+307;
28 static const double twoM500
= 3.054936363499605e-151;
29 static const double twoM600
= 2.4099198651028841e-181;
30 static const double pdnum
= 2.225073858507201e-308;
32 /* __ieee754_hypot(x,y)
34 * This a FP only version without any FP->INT conversion.
35 * It is similar to default C version, making appropriates
36 * overflow and underflows checks as well scaling when it
41 /* POWER7 isinf and isnan optimization are fast. */
42 # define TEST_INF_NAN(x, y) \
43 if (isinf(x) || isinf(y)) \
45 if (isnan(x) || isnan(y)) \
48 /* For POWER6 and below isinf/isnan triggers LHS and PLT calls are
49 * costly (especially for POWER6). */
50 # define GET_TW0_HIGH_WORD(d1,d2,i1,i2) \
52 ieee_double_shape_type gh_u1; \
53 ieee_double_shape_type gh_u2; \
56 (i1) = gh_u1.parts.msw; \
57 (i2) = gh_u2.parts.msw; \
60 # define TEST_INF_NAN(x, y) \
63 GET_TW0_HIGH_WORD(x, y, hx, hy); \
65 uint32_t ht = hx; hx = hy; hy = ht; \
67 if (hx >= 0x7ff00000) { \
68 if (hx == 0x7ff00000 || hy == 0x7ff00000) \
78 __ieee754_hypot (double x
, double y
)
91 if (y
== 0.0 || (x
/ y
) > two60
)
99 return __ieee754_sqrt (x
* x
+ y
* y
) / twoM600
;
107 return __ieee754_sqrt (x
* x
+ y
* y
) / two1022
;
113 return __ieee754_sqrt (x
* x
+ y
* y
) / two600
;
116 return __ieee754_sqrt (x
* x
+ y
* y
);
118 strong_alias (__ieee754_hypot
, __hypot_finite
)