compare.h 1.54 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1 2 3 4
/*
  This file is part of CDO. CDO is a collection of Operators to
  manipulate and analyse Climate model Data.

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
  Copyright (C) 2003-2018 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6 7 8 9 10 11 12 13 14 15 16 17
  See COPYING file for copying and redistribution conditions.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

18 19
#ifndef  COMPARE_H
#define  COMPARE_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
20

21 22
#ifdef  HAVE_CONFIG_H
#include "config.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
23 24
#endif

25
#include <cmath>
26
#include <string.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
27

28
#ifdef  __xlC__  /* performance problem on IBM */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
29 30 31 32 33 34
#ifndef DBL_IS_NAN
#  define DBL_IS_NAN(x)     ((x) != (x))
#endif
#else
#ifndef DBL_IS_NAN
#if defined(HAVE_DECL_ISNAN)
35
#  define DBL_IS_NAN(x)     (std::isnan(x))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#elif defined(FP_NAN)
#  define DBL_IS_NAN(x)     (fpclassify(x) == FP_NAN)
#else
#  define DBL_IS_NAN(x)     ((x) != (x))
#endif
#endif
#endif

#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif

#ifndef IS_EQUAL
#  define IS_NOT_EQUAL(x,y) (x < y || y < x)
#  define IS_EQUAL(x,y)     (!IS_NOT_EQUAL(x,y))
#endif

54 55
#define STR_IS_EQ(x,y) ((*x)==(*y) && strcmp(x,y) == 0)

56
#endif  /* COMPARE_H */