Blame sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c

Packit Service 82fcde
/* Set NaN payload.  dbl-64/wordsize-64 version.
Packit Service 82fcde
   Copyright (C) 2016-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
#include <math.h>
Packit Service 82fcde
#include <math_private.h>
Packit Service 82fcde
#include <libm-alias-double.h>
Packit Service 82fcde
#include <nan-high-order-bit.h>
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
Packit Service 82fcde
#define SET_HIGH_BIT (HIGH_ORDER_BIT_IS_SET_FOR_SNAN ? SIG : !SIG)
Packit Service 82fcde
#define BIAS 0x3ff
Packit Service 82fcde
#define PAYLOAD_DIG 51
Packit Service 82fcde
#define EXPLICIT_MANT_DIG 52
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
FUNC (double *x, double payload)
Packit Service 82fcde
{
Packit Service 82fcde
  uint64_t ix;
Packit Service 82fcde
  EXTRACT_WORDS64 (ix, payload);
Packit Service 82fcde
  int exponent = ix >> EXPLICIT_MANT_DIG;
Packit Service 82fcde
  /* Test if argument is (a) negative or too large; (b) too small,
Packit Service 82fcde
     except for 0 when allowed; (c) not an integer.  */
Packit Service 82fcde
  if (exponent >= BIAS + PAYLOAD_DIG
Packit Service 82fcde
      || (exponent < BIAS && !(SET_HIGH_BIT && ix == 0))
Packit Service 82fcde
      || (ix & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      INSERT_WORDS64 (*x, 0);
Packit Service 82fcde
      return 1;
Packit Service 82fcde
    }
Packit Service 82fcde
  if (ix != 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      ix &= (1ULL << EXPLICIT_MANT_DIG) - 1;
Packit Service 82fcde
      ix |= 1ULL << EXPLICIT_MANT_DIG;
Packit Service 82fcde
      ix >>= BIAS + EXPLICIT_MANT_DIG - exponent;
Packit Service 82fcde
    }
Packit Service 82fcde
  ix |= 0x7ff0000000000000ULL | (SET_HIGH_BIT ? 0x8000000000000ULL : 0);
Packit Service 82fcde
  INSERT_WORDS64 (*x, ix);
Packit Service 82fcde
  return 0;
Packit Service 82fcde
}