| 7727 |
ripley |
1 |
/*
|
|
|
2 |
* R : A Computer Language for Statistical Data Analysis
|
| 84135 |
kalibera |
3 |
* Copyright (C) 1998-2023 The R Core Team
|
| 7727 |
ripley |
4 |
*
|
| 71657 |
plummer |
5 |
* This header file is free software; you can redistribute it and/or modify
|
| 12778 |
pd |
6 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
7 |
* the Free Software Foundation; either version 2.1 of the License, or
|
| 7727 |
ripley |
8 |
* (at your option) any later version.
|
|
|
9 |
*
|
| 71657 |
plummer |
10 |
* This file is part of R. R is distributed under the terms of the
|
|
|
11 |
* GNU General Public License, either Version 2, June 1991 or Version 3,
|
|
|
12 |
* June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
|
|
|
13 |
*
|
| 7727 |
ripley |
14 |
* This program is distributed in the hope that it will be useful,
|
|
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12778 |
pd |
17 |
* GNU Lesser General Public License for more details.
|
| 7727 |
ripley |
18 |
*
|
| 12778 |
pd |
19 |
* You should have received a copy of the GNU Lesser General Public License
|
| 42308 |
ripley |
20 |
* along with this program; if not, a copy is available at
|
| 68949 |
ripley |
21 |
* https://www.R-project.org/Licenses/
|
| 7727 |
ripley |
22 |
*/
|
|
|
23 |
|
| 86515 |
luke |
24 |
/* Included by R.h: Part of the API. */
|
| 60253 |
ripley |
25 |
|
| 7727 |
ripley |
26 |
#ifndef R_COMPLEX_H
|
|
|
27 |
#define R_COMPLEX_H
|
|
|
28 |
|
| 11211 |
ripley |
29 |
#ifdef __cplusplus
|
|
|
30 |
extern "C" {
|
|
|
31 |
#endif
|
|
|
32 |
|
| 84135 |
kalibera |
33 |
# ifdef R_LEGACY_RCOMPLEX
|
|
|
34 |
|
|
|
35 |
/* This definition does not work with optimizing compilers which take
|
|
|
36 |
advantage of strict aliasing rules. It is not safe to use with Fortran
|
|
|
37 |
COMPLEX*16 (PR#18430) or in arguments to library calls expecting C99
|
| 84153 |
kalibera |
38 |
_Complex double. This definition should not be used, but if it were still
|
|
|
39 |
necessary, one should at least disable LTO.
|
|
|
40 |
*/
|
| 84135 |
kalibera |
41 |
|
| 7727 |
ripley |
42 |
typedef struct {
|
| 84135 |
kalibera |
43 |
double r;
|
|
|
44 |
double i;
|
|
|
45 |
} Rcomplex;
|
|
|
46 |
|
|
|
47 |
# else
|
|
|
48 |
|
|
|
49 |
/* This definition uses an anonymous structure, which is defined in C11 (but
|
|
|
50 |
not C99). It is, however, supported at least by GCC, clang and icc. The
|
|
|
51 |
private_data_c member should never be used in code, but tells the compiler
|
|
|
52 |
about type punning when accessing the .r and .i elements, so is safer to use
|
|
|
53 |
when interfacing with Fortran COMPLEX*16 or directly C99 _Complex double
|
|
|
54 |
(PR#18430).
|
|
|
55 |
|
|
|
56 |
This form of static initialization works with both definitions:
|
| 84153 |
kalibera |
57 |
Rcomplex z = { .r = 1, .i = 2 };
|
| 84135 |
kalibera |
58 |
|
| 84218 |
ripley |
59 |
Anonymous structures and C99 _Complex have not been incorporated into C++
|
| 84153 |
kalibera |
60 |
standard. While they are usually supported as compiler extensions, warnings
|
|
|
61 |
are typically issued (-pedantic) by a C++ compiler.
|
|
|
62 |
*/
|
|
|
63 |
|
| 84218 |
ripley |
64 |
#ifdef __cplusplus
|
| 85055 |
ripley |
65 |
// Look for clang first as it defines __GNUC__ and reacts to #pragma GCC
|
| 84218 |
ripley |
66 |
# if defined(__clang__)
|
|
|
67 |
# pragma clang diagnostic push
|
|
|
68 |
# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
|
|
|
69 |
# pragma clang diagnostic ignored "-Wc99-extensions"
|
|
|
70 |
# elif defined(__GNUC__)
|
|
|
71 |
# pragma GCC diagnostic push
|
|
|
72 |
# pragma GCC diagnostic ignored "-Wpedantic"
|
|
|
73 |
# endif
|
|
|
74 |
#endif
|
|
|
75 |
|
| 84135 |
kalibera |
76 |
typedef union {
|
|
|
77 |
struct {
|
| 7727 |
ripley |
78 |
double r;
|
|
|
79 |
double i;
|
| 84135 |
kalibera |
80 |
};
|
|
|
81 |
double _Complex private_data_c;
|
| 7727 |
ripley |
82 |
} Rcomplex;
|
|
|
83 |
|
| 84218 |
ripley |
84 |
#ifdef __cplusplus
|
|
|
85 |
# if defined(__clang__)
|
|
|
86 |
# pragma clang diagnostic pop
|
|
|
87 |
# elif defined(__GNUC__)
|
| 84219 |
ripley |
88 |
# pragma GCC diagnostic pop
|
| 84218 |
ripley |
89 |
# endif
|
|
|
90 |
#endif
|
|
|
91 |
|
| 84135 |
kalibera |
92 |
# endif
|
|
|
93 |
|
| 11211 |
ripley |
94 |
#ifdef __cplusplus
|
|
|
95 |
}
|
| 7727 |
ripley |
96 |
#endif
|
| 11211 |
ripley |
97 |
|
|
|
98 |
#endif /* R_COMPLEX_H */
|