|
Packit Service |
82fcde |
/* Round long double to integer away from zero.
|
|
Packit Service |
82fcde |
Copyright (C) 1997-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
|
|
Packit Service |
82fcde |
Jakub Jelinek <jj@ultra.linux.cz>, 1999.
|
|
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 |
#include <math.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <math_private.h>
|
|
Packit Service |
82fcde |
#include <libm-alias-ldouble.h>
|
|
Packit Service |
df358f |
#include <math-use-builtins.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
_Float128
|
|
Packit Service |
82fcde |
__roundl (_Float128 x)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
df358f |
#if USE_ROUNDL_BUILTIN
|
|
Packit Service |
df358f |
return __builtin_roundl (x);
|
|
Packit Service |
df358f |
#else
|
|
Packit Service |
df358f |
/* Use generic implementation. */
|
|
Packit Service |
82fcde |
int32_t j0;
|
|
Packit Service |
82fcde |
uint64_t i1, i0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
GET_LDOUBLE_WORDS64 (i0, i1, x);
|
|
Packit Service |
82fcde |
j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
|
|
Packit Service |
82fcde |
if (j0 < 48)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (j0 < 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
i0 &= 0x8000000000000000ULL;
|
|
Packit Service |
82fcde |
if (j0 == -1)
|
|
Packit Service |
82fcde |
i0 |= 0x3fff000000000000LL;
|
|
Packit Service |
82fcde |
i1 = 0;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
uint64_t i = 0x0000ffffffffffffLL >> j0;
|
|
Packit Service |
82fcde |
if (((i0 & i) | i1) == 0)
|
|
Packit Service |
82fcde |
/* X is integral. */
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
i0 += 0x0000800000000000LL >> j0;
|
|
Packit Service |
82fcde |
i0 &= ~i;
|
|
Packit Service |
82fcde |
i1 = 0;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else if (j0 > 111)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (j0 == 0x4000)
|
|
Packit Service |
82fcde |
/* Inf or NaN. */
|
|
Packit Service |
82fcde |
return x + x;
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
uint64_t i = -1ULL >> (j0 - 48);
|
|
Packit Service |
82fcde |
if ((i1 & i) == 0)
|
|
Packit Service |
82fcde |
/* X is integral. */
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
uint64_t j = i1 + (1LL << (111 - j0));
|
|
Packit Service |
82fcde |
if (j < i1)
|
|
Packit Service |
82fcde |
i0 += 1;
|
|
Packit Service |
82fcde |
i1 = j;
|
|
Packit Service |
82fcde |
i1 &= ~i;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
SET_LDOUBLE_WORDS64 (x, i0, i1);
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
df358f |
#endif /* ! USE_ROUNDL_BUILTIN */
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
libm_alias_ldouble (__round, round)
|