Blame math/math-underflow.h

Packit 6c4009
/* Check for underflow and force underflow exceptions.
Packit 6c4009
   Copyright (C) 2015-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _MATH_UNDERFLOW_H
Packit 6c4009
#define _MATH_UNDERFLOW_H	1
Packit 6c4009
Packit 6c4009
#include <float.h>
Packit 6c4009
#include <math.h>
Packit 6c4009
Packit 6c4009
#include <math-barriers.h>
Packit 6c4009
Packit 6c4009
#define fabs_tg(x) __MATH_TG ((x), (__typeof (x)) __builtin_fabs, (x))
Packit 6c4009
Packit 6c4009
/* These must be function-like macros because some __MATH_TG
Packit 6c4009
   implementations macro-expand the function-name argument before
Packit 6c4009
   concatenating a suffix to it.  */
Packit 6c4009
#define min_of_type_f() FLT_MIN
Packit 6c4009
#define min_of_type_() DBL_MIN
Packit 6c4009
#define min_of_type_l() LDBL_MIN
Packit 6c4009
#define min_of_type_f128() FLT128_MIN
Packit 6c4009
Packit 6c4009
#define min_of_type(x) __MATH_TG ((x), (__typeof (x)) min_of_type_, ())
Packit 6c4009
Packit 6c4009
/* If X (which is not a NaN) is subnormal, force an underflow
Packit 6c4009
   exception.  */
Packit 6c4009
#define math_check_force_underflow(x)				\
Packit 6c4009
  do								\
Packit 6c4009
    {								\
Packit 6c4009
      __typeof (x) force_underflow_tmp = (x);			\
Packit 6c4009
      if (fabs_tg (force_underflow_tmp)				\
Packit 6c4009
	  < min_of_type (force_underflow_tmp))			\
Packit 6c4009
	{							\
Packit 6c4009
	  __typeof (force_underflow_tmp) force_underflow_tmp2	\
Packit 6c4009
	    = force_underflow_tmp * force_underflow_tmp;	\
Packit 6c4009
	  math_force_eval (force_underflow_tmp2);		\
Packit 6c4009
	}							\
Packit 6c4009
    }								\
Packit 6c4009
  while (0)
Packit 6c4009
/* Likewise, but X is also known to be nonnegative.  */
Packit 6c4009
#define math_check_force_underflow_nonneg(x)			\
Packit 6c4009
  do								\
Packit 6c4009
    {								\
Packit 6c4009
      __typeof (x) force_underflow_tmp = (x);			\
Packit 6c4009
      if (force_underflow_tmp					\
Packit 6c4009
	  < min_of_type (force_underflow_tmp))			\
Packit 6c4009
	{							\
Packit 6c4009
	  __typeof (force_underflow_tmp) force_underflow_tmp2	\
Packit 6c4009
	    = force_underflow_tmp * force_underflow_tmp;	\
Packit 6c4009
	  math_force_eval (force_underflow_tmp2);		\
Packit 6c4009
	}							\
Packit 6c4009
    }								\
Packit 6c4009
  while (0)
Packit 6c4009
/* Likewise, for both real and imaginary parts of a complex
Packit 6c4009
   result.  */
Packit 6c4009
#define math_check_force_underflow_complex(x)				\
Packit 6c4009
  do									\
Packit 6c4009
    {									\
Packit 6c4009
      __typeof (x) force_underflow_complex_tmp = (x);			\
Packit 6c4009
      math_check_force_underflow (__real__ force_underflow_complex_tmp); \
Packit 6c4009
      math_check_force_underflow (__imag__ force_underflow_complex_tmp); \
Packit 6c4009
    }									\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
#endif /* math-underflow.h */