1996-03-05 21:41:30 +00:00
|
|
|
/* e_hypotf.c -- float version of e_hypot.c.
|
|
|
|
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ====================================================
|
|
|
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
1997-01-01 15:28:18 +00:00
|
|
|
* software is freely granted, provided that this notice
|
1996-03-05 21:41:30 +00:00
|
|
|
* is preserved.
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
2012-03-09 19:29:16 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <math_private.h>
|
2019-07-16 15:17:22 +00:00
|
|
|
#include <libm-alias-finite.h>
|
1996-03-05 21:41:30 +00:00
|
|
|
|
2011-10-12 15:27:51 +00:00
|
|
|
float
|
|
|
|
__ieee754_hypotf(float x, float y)
|
1996-03-05 21:41:30 +00:00
|
|
|
{
|
2012-03-14 01:08:58 +00:00
|
|
|
double d_x, d_y;
|
|
|
|
int32_t ha, hb;
|
1996-03-05 21:41:30 +00:00
|
|
|
|
|
|
|
GET_FLOAT_WORD(ha,x);
|
|
|
|
ha &= 0x7fffffff;
|
|
|
|
GET_FLOAT_WORD(hb,y);
|
|
|
|
hb &= 0x7fffffff;
|
Fix hypot sNaN handling (bug 20940).
TS 18661-1 generally defines libm functions taking sNaN arguments to
return qNaN and raise "invalid", even for the cases where a
corresponding qNaN argument would not result in a qNaN return. This
includes hypot with one argument being an infinity and the other being
an sNaN. This patch duly fixes hypot implementatations in glibc
(generic and powerpc) to ensure qNaN, computed by arithmetic on the
arguments, is returned in that case.
Various implementations do their checks for infinities and NaNs inline
by manipulating the representations of the arguments. For simplicity,
this patch just uses issignaling to check for sNaN arguments. This
could be inlined like the existing code (with due care about reversed
quiet NaN conventions, for implementations where that is relevant),
but given that all these checks are in cases where it's already known
at least one argument is not finite, which should be the uncommon
case, that doesn't seem worthwhile unless performance issues are
observed in practice.
Tested for x86_64, x86, mips64 and powerpc.
[BZ #20940]
* sysdeps/ieee754/dbl-64/e_hypot.c (__ieee754_hypot): Do not
return Inf for arguments Inf and sNaN.
* sysdeps/ieee754/flt-32/e_hypotf.c (__ieee754_hypotf): Likewise.
* sysdeps/ieee754/ldbl-128/e_hypotl.c (__ieee754_hypotl):
Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_hypotl.c (__ieee754_hypotl):
Likewise.
* sysdeps/ieee754/ldbl-96/e_hypotl.c (__ieee754_hypotl): Likewise.
* sysdeps/powerpc/fpu/e_hypot.c (TEST_INF_NAN): Do not return Inf
for arguments Inf and sNaN. When returning a NaN, compute it by
arithmetic on the arguments.
* sysdeps/powerpc/fpu/e_hypotf.c (TEST_INF_NAN): Likewise.
* math/libm-test.inc (pow_test_data): Add tests of sNaN arguments.
2016-12-07 01:16:36 +00:00
|
|
|
if (ha == 0x7f800000 && !issignaling (y))
|
2015-09-15 17:24:23 +00:00
|
|
|
return fabsf(x);
|
Fix hypot sNaN handling (bug 20940).
TS 18661-1 generally defines libm functions taking sNaN arguments to
return qNaN and raise "invalid", even for the cases where a
corresponding qNaN argument would not result in a qNaN return. This
includes hypot with one argument being an infinity and the other being
an sNaN. This patch duly fixes hypot implementatations in glibc
(generic and powerpc) to ensure qNaN, computed by arithmetic on the
arguments, is returned in that case.
Various implementations do their checks for infinities and NaNs inline
by manipulating the representations of the arguments. For simplicity,
this patch just uses issignaling to check for sNaN arguments. This
could be inlined like the existing code (with due care about reversed
quiet NaN conventions, for implementations where that is relevant),
but given that all these checks are in cases where it's already known
at least one argument is not finite, which should be the uncommon
case, that doesn't seem worthwhile unless performance issues are
observed in practice.
Tested for x86_64, x86, mips64 and powerpc.
[BZ #20940]
* sysdeps/ieee754/dbl-64/e_hypot.c (__ieee754_hypot): Do not
return Inf for arguments Inf and sNaN.
* sysdeps/ieee754/flt-32/e_hypotf.c (__ieee754_hypotf): Likewise.
* sysdeps/ieee754/ldbl-128/e_hypotl.c (__ieee754_hypotl):
Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_hypotl.c (__ieee754_hypotl):
Likewise.
* sysdeps/ieee754/ldbl-96/e_hypotl.c (__ieee754_hypotl): Likewise.
* sysdeps/powerpc/fpu/e_hypot.c (TEST_INF_NAN): Do not return Inf
for arguments Inf and sNaN. When returning a NaN, compute it by
arithmetic on the arguments.
* sysdeps/powerpc/fpu/e_hypotf.c (TEST_INF_NAN): Likewise.
* math/libm-test.inc (pow_test_data): Add tests of sNaN arguments.
2016-12-07 01:16:36 +00:00
|
|
|
else if (hb == 0x7f800000 && !issignaling (x))
|
2015-09-15 17:24:23 +00:00
|
|
|
return fabsf(y);
|
2012-03-14 01:08:58 +00:00
|
|
|
else if (ha > 0x7f800000 || hb > 0x7f800000)
|
|
|
|
return fabsf(x) * fabsf(y);
|
|
|
|
else if (ha == 0)
|
|
|
|
return fabsf(y);
|
|
|
|
else if (hb == 0)
|
|
|
|
return fabsf(x);
|
|
|
|
|
|
|
|
d_x = (double) x;
|
|
|
|
d_y = (double) y;
|
|
|
|
|
2018-03-15 18:05:03 +00:00
|
|
|
return (float) sqrt(d_x * d_x + d_y * d_y);
|
1996-03-05 21:41:30 +00:00
|
|
|
}
|
2019-07-16 15:17:22 +00:00
|
|
|
#ifndef __ieee754_hypotf
|
|
|
|
libm_alias_finite (__ieee754_hypotf, __hypotf)
|
|
|
|
#endif
|