|
Packit Service |
82fcde |
/* Round 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.
|
|
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-double.h>
|
|
Packit Service |
bd3911 |
#include <stdint.h>
|
|
Packit Service |
df358f |
#include <math-use-builtins.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
double
|
|
Packit Service |
82fcde |
__round (double x)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
df358f |
#if USE_ROUND_BUILTIN
|
|
Packit Service |
df358f |
return __builtin_round (x);
|
|
Packit Service |
df358f |
#else
|
|
Packit Service |
df358f |
/* Use generic implementation. */
|
|
Packit Service |
bd3911 |
int64_t i0, j0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
bd3911 |
EXTRACT_WORDS64 (i0, x);
|
|
Packit Service |
bd3911 |
j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
|
|
Packit Service |
bd3911 |
if (__glibc_likely (j0 < 52))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (j0 < 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
bd3911 |
i0 &= UINT64_C (0x8000000000000000);
|
|
Packit Service |
82fcde |
if (j0 == -1)
|
|
Packit Service |
bd3911 |
i0 |= UINT64_C (0x3ff0000000000000);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
bd3911 |
uint64_t i = UINT64_C (0x000fffffffffffff) >> j0;
|
|
Packit Service |
bd3911 |
if ((i0 & i) == 0)
|
|
Packit Service |
82fcde |
/* X is integral. */
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
bd3911 |
i0 += UINT64_C (0x0008000000000000) >> j0;
|
|
Packit Service |
82fcde |
i0 &= ~i;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
bd3911 |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (j0 == 0x400)
|
|
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 |
|
|
Packit Service |
bd3911 |
INSERT_WORDS64 (x, i0);
|
|
Packit Service |
82fcde |
return x;
|
|
Packit Service |
df358f |
#endif /* ! USE_ROUND_BUILTIN */
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
libm_alias_double (__round, round)
|