|
Packit Service |
82fcde |
/* Round to int long double floating-point values.
|
|
Packit Service |
82fcde |
IBM extended format long double version.
|
|
Packit Service |
82fcde |
Copyright (C) 2006-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* This has been coded in assembler because GCC makes such a mess of it
|
|
Packit Service |
82fcde |
when it's coded in C. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <math.h>
|
|
Packit Service |
82fcde |
#include <math_private.h>
|
|
Packit Service |
82fcde |
#include <math_ldbl_opt.h>
|
|
Packit Service |
82fcde |
#include <float.h>
|
|
Packit Service |
82fcde |
#include <ieee754.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
long double
|
|
Packit Service |
82fcde |
__roundl (long double x)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
double xh, xl, hi, lo;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
ldbl_unpack (x, &xh, &xl);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Return Inf, Nan, +/-0 unchanged. */
|
|
Packit Service |
82fcde |
if (__builtin_expect (xh != 0.0
|
|
Packit Service |
82fcde |
&& __builtin_isless (__builtin_fabs (xh),
|
|
Packit Service |
82fcde |
__builtin_inf ()), 1))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
hi = __round (xh);
|
|
Packit Service |
82fcde |
if (hi != xh)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* The high part is not an integer; the low part only
|
|
Packit Service |
82fcde |
affects the result if the high part is exactly half way
|
|
Packit Service |
82fcde |
between two integers and the low part is nonzero with the
|
|
Packit Service |
82fcde |
opposite sign. */
|
|
Packit Service |
82fcde |
if (fabs (hi - xh) == 0.5)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (xh > 0 && xl < 0)
|
|
Packit Service |
82fcde |
xh = hi - 1;
|
|
Packit Service |
82fcde |
else if (xh < 0 && xl > 0)
|
|
Packit Service |
82fcde |
xh = hi + 1;
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
xh = hi;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
xh = hi;
|
|
Packit Service |
82fcde |
xl = 0;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* The high part is a nonzero integer. */
|
|
Packit Service |
82fcde |
lo = __round (xl);
|
|
Packit Service |
82fcde |
if (fabs (lo - xl) == 0.5)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (xh > 0 && xl < 0)
|
|
Packit Service |
82fcde |
xl = lo + 1;
|
|
Packit Service |
82fcde |
else if (xh < 0 && lo > 0)
|
|
Packit Service |
82fcde |
xl = lo - 1;
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
xl = lo;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
xl = lo;
|
|
Packit Service |
82fcde |
xh = hi;
|
|
Packit Service |
82fcde |
ldbl_canonicalize_int (&xh, &xl);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
/* Quiet signaling NaN arguments. */
|
|
Packit Service |
82fcde |
xh += xh;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return ldbl_pack (xh, xl);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
long_double_symbol (libm, __roundl, roundl);
|