Blame include/rounding-mode.h

Packit Service 82fcde
/* Handle floating-point rounding mode within libc.
Packit Service 82fcde
   Copyright (C) 2012-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
#ifndef _ROUNDING_MODE_H
Packit Service 82fcde
#define _ROUNDING_MODE_H	1
Packit Service 82fcde
Packit Service 82fcde
#include <fenv.h>
Packit Service 82fcde
#include <stdbool.h>
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
Packit Service 82fcde
/* Get the architecture-specific definition of how to determine the
Packit Service 82fcde
   rounding mode in libc.  This header must also define the FE_*
Packit Service 82fcde
   macros for any standard rounding modes the architecture does not
Packit Service 82fcde
   have in <fenv.h>, to arbitrary distinct values.  */
Packit Service 82fcde
#include <get-rounding-mode.h>
Packit Service 82fcde
Packit Service 82fcde
/* Return true if a number should be rounded away from zero in
Packit Service 82fcde
   rounding mode MODE, false otherwise.  NEGATIVE is true if the
Packit Service 82fcde
   number is negative, false otherwise.  LAST_DIGIT_ODD is true if the
Packit Service 82fcde
   last digit of the truncated value (last bit for binary) is odd,
Packit Service 82fcde
   false otherwise.  HALF_BIT is true if the number is at least half
Packit Service 82fcde
   way from the truncated value to the next value with the
Packit Service 82fcde
   least-significant digit in the same place, false otherwise.
Packit Service 82fcde
   MORE_BITS is true if the number is not exactly equal to the
Packit Service 82fcde
   truncated value or the half-way value, false otherwise.  */
Packit Service 82fcde
Packit Service 82fcde
static bool
Packit Service 82fcde
round_away (bool negative, bool last_digit_odd, bool half_bit, bool more_bits,
Packit Service 82fcde
	    int mode)
Packit Service 82fcde
{
Packit Service 82fcde
  switch (mode)
Packit Service 82fcde
    {
Packit Service 82fcde
    case FE_DOWNWARD:
Packit Service 82fcde
      return negative && (half_bit || more_bits);
Packit Service 82fcde
Packit Service 82fcde
    case FE_TONEAREST:
Packit Service 82fcde
      return half_bit && (last_digit_odd || more_bits);
Packit Service 82fcde
Packit Service 82fcde
    case FE_TOWARDZERO:
Packit Service 82fcde
      return false;
Packit Service 82fcde
Packit Service 82fcde
    case FE_UPWARD:
Packit Service 82fcde
      return !negative && (half_bit || more_bits);
Packit Service 82fcde
Packit Service 82fcde
    default:
Packit Service 82fcde
      abort ();
Packit Service 82fcde
    }
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#endif /* rounding-mode.h */