RAPI
R_ext/Arith.h
Go to the documentation of this file.
00001 /*
00002  *  R : A Computer Language for Statistical Data Analysis
00003  *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
00004  *  Copyright (C) 1998--2016  The R Core Team.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU Lesser General Public License as published by
00008  *  the Free Software Foundation; either version 2.1 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU Lesser General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Lesser General Public License
00017  *  along with this program; if not, a copy is available at
00018  *  https://www.R-project.org/Licenses/
00019  */
00020 
00021 /* Included by R.h: API */
00022 
00023 #ifndef R_ARITH_H_
00024 #define R_ARITH_H_
00025 
00026 /* 
00027    This used to define _BSD_SOURCE to make declarations of isfinite
00028    and isnan visible in glibc.  But that was deprecated in glibc 2.20,
00029    and --std=c99 suffices nowadays.
00030 */
00031 
00032 #include <R_ext/libextern.h>
00033 #ifdef  __cplusplus
00034 extern "C" {
00035 #elif !defined(NO_C_HEADERS)
00036 /* needed for isnan and isfinite, neither of which are used under C++ */
00037 # include <math.h>
00038 #endif
00039 
00040 /* implementation of these : ../../main/arithmetic.c */
00041 LibExtern double R_NaN;     /* IEEE NaN */
00042 LibExtern double R_PosInf;  /* IEEE Inf */
00043 LibExtern double R_NegInf;  /* IEEE -Inf */
00044 LibExtern double R_NaReal;  /* NA_REAL: IEEE */
00045 LibExtern int    R_NaInt;   /* NA_INTEGER:= INT_MIN currently */
00046 #ifdef __MAIN__
00047 #undef extern
00048 #undef LibExtern
00049 #endif
00050 
00051 #define NA_LOGICAL  R_NaInt
00052 #define NA_INTEGER  R_NaInt
00053 /* #define NA_FACTOR    R_NaInt  unused */
00054 #define NA_REAL     R_NaReal
00055 /* NA_STRING is a SEXP, so defined in Rinternals.h */
00056 
00057 int R_IsNA(double x);       /* True for R's NA only */
00058 int R_IsNaN(double x);      /* True for special NaN, *not* for NA */
00059 int R_finite(double x);     /* True if none of NA, NaN, +/-Inf */
00060 #define ISNA(x)        R_IsNA(x)
00061 
00062 /* ISNAN(): True for *both* NA and NaN.
00063    NOTE: some systems do not return 1 for TRUE.
00064    Also note that C++ math headers specifically undefine
00065    isnan if it is a macro (it is on macOS and in C99),
00066    hence the workaround.  This code also appears in Rmath.h
00067 */
00068 #ifdef __cplusplus
00069   int R_isnancpp(double); /* in arithmetic.c */
00070 #  define ISNAN(x)     R_isnancpp(x)
00071 #else
00072 #  define ISNAN(x)     (isnan(x)!=0)
00073 #endif
00074 
00075 /* The following is only defined inside R */
00076 #ifdef HAVE_WORKING_ISFINITE
00077 /* isfinite is defined in <math.h> according to C99 */
00078 # define R_FINITE(x)    isfinite(x)
00079 #else
00080 # define R_FINITE(x)    R_finite(x)
00081 #endif
00082 
00083 #ifdef  __cplusplus
00084 }
00085 #endif
00086 
00087 #endif /* R_ARITH_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines