(root)/
gettext-0.22.4/
gnulib-local/
lib/
libxml/
trionan.c
       1  /* NaNs and Infinity in floating-point numbers.
       2     Copyright (C) 2015-2023 Free Software Foundation, Inc.
       3  
       4     This file was written by Daiki Ueno <ueno@gnu.org>, 2015.
       5  
       6     This program is free software: you can redistribute it and/or modify
       7     it under the terms of the GNU General Public License as published by
       8     the Free Software Foundation; either version 3 of the License, or
       9     (at your option) any later version.
      10  
      11     This program is distributed in the hope that it will be useful,
      12     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14     GNU General Public License for more details.
      15  
      16     You should have received a copy of the GNU General Public License
      17     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      18  
      19  /* Replacement 'trionan.c', using Gnulib functions.  */
      20  
      21  #include "config.h"
      22  #include <float.h>
      23  #include <math.h>
      24  
      25  /* Copied from gnulib/tests/infinity.h.  */
      26  
      27  /* Infinityd () returns a 'double' +Infinity.  */
      28  
      29  /* The Microsoft MSVC 9 compiler chokes on the expression 1.0 / 0.0.  */
      30  #if defined _MSC_VER
      31  static double
      32  Infinityd ()
      33  {
      34    static double zero = 0.0;
      35    return 1.0 / zero;
      36  }
      37  #else
      38  # define Infinityd() (1.0 / 0.0)
      39  #endif
      40  
      41  /* Copied from gnulib/tests/nan.h.  */
      42  
      43  /* NaNd () returns a 'double' not-a-number.  */
      44  
      45  /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke
      46     on the expression 0.0 / 0.0.  */
      47  #if defined __DECC || defined _MSC_VER
      48  static double
      49  NaNd ()
      50  {
      51    static double zero = 0.0;
      52    return zero / zero;
      53  }
      54  #else
      55  # define NaNd() (0.0 / 0.0)
      56  #endif
      57  
      58  /* Copied from gnulib/tests/minus-zero.h.  */
      59  
      60  /* minus_zerod represents the value -0.0.  */
      61  
      62  /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
      63     ICC 10.0 has a bug when optimizing the expression -zero.
      64     The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
      65     to PowerPC on Mac OS X 10.5.  */
      66  #if defined __hpux || defined __sgi || defined __ICC
      67  _GL_ATTRIBUTE_MAYBE_UNUSED
      68  static double
      69  compute_minus_zerod (void)
      70  {
      71    return -DBL_MIN * DBL_MIN;
      72  }
      73  # define minus_zerod compute_minus_zerod ()
      74  #else
      75  _GL_ATTRIBUTE_MAYBE_UNUSED
      76  static double minus_zerod = -0.0;
      77  #endif
      78  
      79  #undef INFINITY
      80  #undef NAN
      81  
      82  #define INFINITY Infinityd()
      83  #define NAN NaNd()
      84  
      85  #define trio_pinf() INFINITY
      86  #define trio_ninf() -INFINITY
      87  #define trio_nan() NAN
      88  #define trio_nzero() minus_zerod
      89  
      90  #define trio_isnan(x) isnan(x)
      91  #define trio_isinf(x) isinf(x)
      92  #define trio_signbit(x) signbit(x)