Blame sysdeps/ieee754/dbl-64/s_totalorder.c

Packit Service 82fcde
/* Total order operation.  dbl-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
int
Packit Service 82fcde
__totalorder (double x, double y)
Packit Service 82fcde
{
Packit Service 82fcde
  int32_t hx, hy;
Packit Service 82fcde
  uint32_t lx, ly;
Packit Service 82fcde
  EXTRACT_WORDS (hx, lx, x);
Packit Service 82fcde
  EXTRACT_WORDS (hy, ly, y);
Packit Service 82fcde
#if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
Packit Service 82fcde
  uint32_t uhx = hx & 0x7fffffff, uhy = hy & 0x7fffffff;
Packit Service 82fcde
  /* For the preferred quiet NaN convention, this operation is a
Packit Service 82fcde
     comparison of the representations of the arguments interpreted as
Packit Service 82fcde
     sign-magnitude integers.  If both arguments are NaNs, invert the
Packit Service 82fcde
     quiet/signaling bit so comparing that way works.  */
Packit Service 82fcde
  if ((uhx > 0x7ff00000 || (uhx == 0x7ff00000 && lx != 0))
Packit Service 82fcde
      && (uhy > 0x7ff00000 || (uhy == 0x7ff00000 && ly != 0)))
Packit Service 82fcde
    {
Packit Service 82fcde
      hx ^= 0x00080000;
Packit Service 82fcde
      hy ^= 0x00080000;
Packit Service 82fcde
    }
Packit Service 82fcde
#endif
Packit Service 82fcde
  uint32_t hx_sign = hx >> 31;
Packit Service 82fcde
  uint32_t hy_sign = hy >> 31;
Packit Service 82fcde
  hx ^= hx_sign >> 1;
Packit Service 82fcde
  lx ^= hx_sign;
Packit Service 82fcde
  hy ^= hy_sign >> 1;
Packit Service 82fcde
  ly ^= hy_sign;
Packit Service 82fcde
  return hx < hy || (hx == hy && lx <= ly);
Packit Service 82fcde
}
Packit Service 82fcde
libm_alias_double (__totalorder, totalorder)