|
Packit |
6c4009 |
/* Implement __kernel_standard_l.
|
|
Packit |
6c4009 |
Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
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 Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the 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 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Parts based on k_standard.c from fdlibm: */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* @(#)k_standard.c 5.1 93/09/24 */
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math-barriers.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <math-svid-compat.h>
|
|
Packit |
6c4009 |
#include <fenv.h>
|
|
Packit |
6c4009 |
#include <float.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if LIBM_SVID_COMPAT
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static double zero = 0.0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Handle errors for a libm function as specified by TYPE (see
|
|
Packit |
6c4009 |
comments in k_standard.c for details), with arguments X and Y,
|
|
Packit |
6c4009 |
returning the appropriate return value for that function. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
long double
|
|
Packit |
6c4009 |
__kernel_standard_l (long double x, long double y, int type)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
double dx, dy;
|
|
Packit |
6c4009 |
struct exception exc;
|
|
Packit |
6c4009 |
fenv_t env;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
feholdexcept (&env;;
|
|
Packit |
6c4009 |
dx = x;
|
|
Packit |
6c4009 |
dy = y;
|
|
Packit |
6c4009 |
math_force_eval (dx);
|
|
Packit |
6c4009 |
math_force_eval (dy);
|
|
Packit |
6c4009 |
fesetenv (&env;;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
switch (type)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
case 221:
|
|
Packit |
6c4009 |
/* powl (x, y) overflow. */
|
|
Packit |
6c4009 |
exc.arg1 = dx;
|
|
Packit |
6c4009 |
exc.arg2 = dy;
|
|
Packit |
6c4009 |
exc.type = OVERFLOW;
|
|
Packit |
6c4009 |
exc.name = (char *) "powl";
|
|
Packit |
6c4009 |
if (_LIB_VERSION == _SVID_)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
exc.retval = HUGE;
|
|
Packit |
6c4009 |
y *= 0.5;
|
|
Packit |
6c4009 |
if (x < zero && __rintl (y) != y)
|
|
Packit |
6c4009 |
exc.retval = -HUGE;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
exc.retval = HUGE_VAL;
|
|
Packit |
6c4009 |
y *= 0.5;
|
|
Packit |
6c4009 |
if (x < zero && __rintl (y) != y)
|
|
Packit |
6c4009 |
exc.retval = -HUGE_VAL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (_LIB_VERSION == _POSIX_)
|
|
Packit |
6c4009 |
__set_errno (ERANGE);
|
|
Packit |
6c4009 |
else if (!matherr (&exc))
|
|
Packit |
6c4009 |
__set_errno (ERANGE);
|
|
Packit |
6c4009 |
return exc.retval;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
case 222:
|
|
Packit |
6c4009 |
/* powl (x, y) underflow. */
|
|
Packit |
6c4009 |
exc.arg1 = dx;
|
|
Packit |
6c4009 |
exc.arg2 = dy;
|
|
Packit |
6c4009 |
exc.type = UNDERFLOW;
|
|
Packit |
6c4009 |
exc.name = (char *) "powl";
|
|
Packit |
6c4009 |
exc.retval = zero;
|
|
Packit |
6c4009 |
y *= 0.5;
|
|
Packit |
6c4009 |
if (x < zero && __rintl (y) != y)
|
|
Packit |
6c4009 |
exc.retval = -zero;
|
|
Packit |
6c4009 |
if (_LIB_VERSION == _POSIX_)
|
|
Packit |
6c4009 |
__set_errno (ERANGE);
|
|
Packit |
6c4009 |
else if (!matherr (&exc))
|
|
Packit |
6c4009 |
__set_errno (ERANGE);
|
|
Packit |
6c4009 |
return exc.retval;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
default:
|
|
Packit |
6c4009 |
return __kernel_standard (dx, dy, type);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif
|