The R Project SVN R

Rev

Rev 59039 | Rev 68029 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7727 ripley 1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
59039 ripley 4
 *  Copyright (C) 1998--2007  The R Core Team.
7727 ripley 5
 *
6
 *  This program is free software; you can redistribute it and/or modify
12778 pd 7
 *  it under the terms of the GNU Lesser General Public License as published by
8
 *  the Free Software Foundation; either version 2.1 of the License, or
7727 ripley 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
12778 pd 14
 *  GNU Lesser General Public License for more details.
7727 ripley 15
 *
12778 pd 16
 *  You should have received a copy of the GNU Lesser General Public License
42308 ripley 17
 *  along with this program; if not, a copy is available at
18
 *  http://www.r-project.org/Licenses/
7727 ripley 19
 */
20
 
60253 ripley 21
/* Included by R.h: API */
22
 
7727 ripley 23
#ifndef R_ARITH_H_
24
#define R_ARITH_H_
25
 
42724 ripley 26
/* Only for use where config.h has not already been included */
36498 ripley 27
#if defined(HAVE_GLIBC2) && !defined(_BSD_SOURCE)
28
/* ensure that finite and isnan are declared */
29
# define _BSD_SOURCE 1
30
#endif
7727 ripley 31
 
15716 ripley 32
#include <R_ext/libextern.h>
11211 ripley 33
#ifdef  __cplusplus
34
extern "C" {
42409 ripley 35
#elif !defined(NO_C_HEADERS)
42396 ripley 36
/* needed for isnan and isfinite, neither of which are used under C++ */
37
# include <math.h>
11211 ripley 38
#endif
39
 
9264 maechler 40
/* implementation of these : ../../main/arithmetic.c */
29423 ripley 41
LibExtern double R_NaN;		/* IEEE NaN */
42
LibExtern double R_PosInf;	/* IEEE Inf */
43
LibExtern double R_NegInf;	/* IEEE -Inf */
44
LibExtern double R_NaReal;	/* NA_REAL: IEEE */
15716 ripley 45
LibExtern int	 R_NaInt;	/* NA_INTEGER:= INT_MIN currently */
7727 ripley 46
#ifdef __MAIN__
47
#undef extern
15716 ripley 48
#undef LibExtern
7727 ripley 49
#endif
50
 
51
#define NA_LOGICAL	R_NaInt
52
#define NA_INTEGER	R_NaInt
29423 ripley 53
/* #define NA_FACTOR	R_NaInt  unused */
7727 ripley 54
#define NA_REAL		R_NaReal
55
/* NA_STRING is a SEXP, so defined in Rinternals.h */
56
 
57
int R_IsNA(double);		/* True for R's NA only */
58
int R_IsNaN(double);		/* True for special NaN, *not* for NA */
9264 maechler 59
int R_finite(double);		/* True if none of NA, NaN, +/-Inf */
48943 maechler 60
#define ISNA(x)	       R_IsNA(x)
7727 ripley 61
 
48943 maechler 62
/* ISNAN(): True for *both* NA and NaN.
63
   NOTE: some systems do not return 1 for TRUE.
32538 tlumley 64
   Also note that C++ math headers specifically undefine
65
   isnan if it is a macro (it is on OS X and in C99),
66
   hence the workaround.  This code also appears in Rmath.h
67
*/
68
#ifdef __cplusplus
69
  int R_isnancpp(double); /* in arithmetic.c */
70
#  define ISNAN(x)     R_isnancpp(x)
71
#else
72
#  define ISNAN(x)     (isnan(x)!=0)
73
#endif
74
 
42394 ripley 75
/* The following is only defined inside R */
29441 ripley 76
#ifdef HAVE_WORKING_ISFINITE
77
/* isfinite is defined in <math.h> according to C99 */
78
# define R_FINITE(x)    isfinite(x)
79
#else
80
# define R_FINITE(x)    R_finite(x)
81
#endif
7727 ripley 82
 
11211 ripley 83
#ifdef  __cplusplus
84
}
7727 ripley 85
#endif
11211 ripley 86
 
87
#endif /* R_ARITH_H_ */