|
Packit |
6c4009 |
/* Pythagorean addition using floats
|
|
Packit |
6c4009 |
Copyright (C) 2011-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Library General Public License as
|
|
Packit |
6c4009 |
published by the Free Software Foundation; either version 2 of the
|
|
Packit |
6c4009 |
License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Library General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Library General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
Packit |
6c4009 |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* __ieee754_hypotf(x,y)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This a FP only version without any FP->INT conversion.
|
|
Packit |
6c4009 |
It is similar to default C version, making appropriates
|
|
Packit |
6c4009 |
overflow and underflows checks as using double precision
|
|
Packit |
6c4009 |
instead of scaling. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef _ARCH_PWR7
|
|
Packit |
6c4009 |
/* POWER7 isinf and isnan optimizations are fast. */
|
|
Packit |
6c4009 |
# define TEST_INF_NAN(x, y) \
|
|
Packit |
6c4009 |
if ((isinff(x) || isinff(y)) \
|
|
Packit |
6c4009 |
&& !issignaling (x) && !issignaling (y)) \
|
|
Packit |
6c4009 |
return INFINITY; \
|
|
Packit |
6c4009 |
if (isnanf(x) || isnanf(y)) \
|
|
Packit |
6c4009 |
return x + y;
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
/* For POWER6 and below isinf/isnan triggers LHS and PLT calls are
|
|
Packit |
6c4009 |
* costly (especially for POWER6). */
|
|
Packit |
6c4009 |
# define GET_TWO_FLOAT_WORD(f1,f2,i1,i2) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
ieee_float_shape_type gf_u1; \
|
|
Packit |
6c4009 |
ieee_float_shape_type gf_u2; \
|
|
Packit |
6c4009 |
gf_u1.value = (f1); \
|
|
Packit |
6c4009 |
gf_u2.value = (f2); \
|
|
Packit |
6c4009 |
(i1) = gf_u1.word & 0x7fffffff; \
|
|
Packit |
6c4009 |
(i2) = gf_u2.word & 0x7fffffff; \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define TEST_INF_NAN(x, y) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
uint32_t hx, hy; \
|
|
Packit |
6c4009 |
GET_TWO_FLOAT_WORD(x, y, hx, hy); \
|
|
Packit |
6c4009 |
if (hy > hx) { \
|
|
Packit |
6c4009 |
uint32_t ht = hx; hx = hy; hy = ht; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
if (hx >= 0x7f800000) { \
|
|
Packit |
6c4009 |
if ((hx == 0x7f800000 || hy == 0x7f800000) \
|
|
Packit |
6c4009 |
&& !issignaling (x) && !issignaling (y)) \
|
|
Packit |
6c4009 |
return INFINITY; \
|
|
Packit |
6c4009 |
return x + y; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
float
|
|
Packit |
6c4009 |
__ieee754_hypotf (float x, float y)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
TEST_INF_NAN (x, y);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return sqrt ((double) x * x + (double) y * y);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
strong_alias (__ieee754_hypotf, __hypotf_finite)
|