| 7727 |
ripley |
1 |
/*
|
|
|
2 |
* R : A Computer Language for Statistical Data Analysis
|
|
|
3 |
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
|
| 69969 |
ripley |
4 |
* Copyright (C) 1998--2016 The R Core Team.
|
| 7727 |
ripley |
5 |
*
|
| 71657 |
plummer |
6 |
* This header file 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 |
*
|
| 71657 |
plummer |
11 |
* This file is part of R. R is distributed under the terms of the
|
|
|
12 |
* GNU General Public License, either Version 2, June 1991 or Version 3,
|
|
|
13 |
* June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
|
|
|
14 |
*
|
| 7727 |
ripley |
15 |
* This program is distributed in the hope that it will be useful,
|
|
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12778 |
pd |
18 |
* GNU Lesser General Public License for more details.
|
| 7727 |
ripley |
19 |
*
|
| 12778 |
pd |
20 |
* You should have received a copy of the GNU Lesser General Public License
|
| 42308 |
ripley |
21 |
* along with this program; if not, a copy is available at
|
| 68949 |
ripley |
22 |
* https://www.R-project.org/Licenses/
|
| 7727 |
ripley |
23 |
*/
|
|
|
24 |
|
| 86515 |
luke |
25 |
/* Included by R.h: Part of the API. */
|
| 60253 |
ripley |
26 |
|
| 7727 |
ripley |
27 |
#ifndef R_ARITH_H_
|
|
|
28 |
#define R_ARITH_H_
|
|
|
29 |
|
| 68035 |
ripley |
30 |
/*
|
| 70010 |
ripley |
31 |
This used to define _BSD_SOURCE to make declarations of isfinite
|
|
|
32 |
and isnan visible in glibc. But that was deprecated in glibc 2.20,
|
|
|
33 |
and --std=c99 suffices nowadays.
|
| 68035 |
ripley |
34 |
*/
|
| 7727 |
ripley |
35 |
|
| 15716 |
ripley |
36 |
#include <R_ext/libextern.h>
|
| 11211 |
ripley |
37 |
#ifdef __cplusplus
|
|
|
38 |
extern "C" {
|
| 71371 |
ripley |
39 |
#else
|
| 42396 |
ripley |
40 |
/* needed for isnan and isfinite, neither of which are used under C++ */
|
|
|
41 |
# include <math.h>
|
| 11211 |
ripley |
42 |
#endif
|
|
|
43 |
|
| 9264 |
maechler |
44 |
/* implementation of these : ../../main/arithmetic.c */
|
| 29423 |
ripley |
45 |
LibExtern double R_NaN; /* IEEE NaN */
|
|
|
46 |
LibExtern double R_PosInf; /* IEEE Inf */
|
|
|
47 |
LibExtern double R_NegInf; /* IEEE -Inf */
|
|
|
48 |
LibExtern double R_NaReal; /* NA_REAL: IEEE */
|
| 15716 |
ripley |
49 |
LibExtern int R_NaInt; /* NA_INTEGER:= INT_MIN currently */
|
| 7727 |
ripley |
50 |
#ifdef __MAIN__
|
|
|
51 |
#undef extern
|
| 15716 |
ripley |
52 |
#undef LibExtern
|
| 7727 |
ripley |
53 |
#endif
|
|
|
54 |
|
|
|
55 |
#define NA_LOGICAL R_NaInt
|
|
|
56 |
#define NA_INTEGER R_NaInt
|
| 29423 |
ripley |
57 |
/* #define NA_FACTOR R_NaInt unused */
|
| 7727 |
ripley |
58 |
#define NA_REAL R_NaReal
|
|
|
59 |
/* NA_STRING is a SEXP, so defined in Rinternals.h */
|
|
|
60 |
|
|
|
61 |
int R_IsNA(double); /* True for R's NA only */
|
|
|
62 |
int R_IsNaN(double); /* True for special NaN, *not* for NA */
|
| 9264 |
maechler |
63 |
int R_finite(double); /* True if none of NA, NaN, +/-Inf */
|
| 48943 |
maechler |
64 |
#define ISNA(x) R_IsNA(x)
|
| 7727 |
ripley |
65 |
|
| 48943 |
maechler |
66 |
/* ISNAN(): True for *both* NA and NaN.
|
|
|
67 |
NOTE: some systems do not return 1 for TRUE.
|
| 32538 |
tlumley |
68 |
Also note that C++ math headers specifically undefine
|
| 70779 |
ripley |
69 |
isnan if it is a macro (it is on macOS and in C99),
|
| 32538 |
tlumley |
70 |
hence the workaround. This code also appears in Rmath.h
|
|
|
71 |
*/
|
|
|
72 |
#ifdef __cplusplus
|
|
|
73 |
int R_isnancpp(double); /* in arithmetic.c */
|
|
|
74 |
# define ISNAN(x) R_isnancpp(x)
|
|
|
75 |
#else
|
|
|
76 |
# define ISNAN(x) (isnan(x)!=0)
|
|
|
77 |
#endif
|
|
|
78 |
|
| 42394 |
ripley |
79 |
/* The following is only defined inside R */
|
| 29441 |
ripley |
80 |
#ifdef HAVE_WORKING_ISFINITE
|
|
|
81 |
/* isfinite is defined in <math.h> according to C99 */
|
|
|
82 |
# define R_FINITE(x) isfinite(x)
|
|
|
83 |
#else
|
|
|
84 |
# define R_FINITE(x) R_finite(x)
|
|
|
85 |
#endif
|
| 7727 |
ripley |
86 |
|
| 11211 |
ripley |
87 |
#ifdef __cplusplus
|
|
|
88 |
}
|
| 7727 |
ripley |
89 |
#endif
|
| 11211 |
ripley |
90 |
|
|
|
91 |
#endif /* R_ARITH_H_ */
|