Ruby
3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
ext
bigdecimal
missing.h
Go to the documentation of this file.
1
#ifndef MISSING_H
2
#define MISSING_H 1
3
4
#if defined(__cplusplus)
5
extern
"C"
{
6
#if 0
7
}
/* satisfy cc-mode */
8
#endif
9
#endif
10
11
#ifdef HAVE_STDLIB_H
12
# include <stdlib.h>
13
#endif
14
15
#ifdef HAVE_MATH_H
16
# include <
math.h
>
17
#endif
18
19
#ifndef RB_UNUSED_VAR
20
# if defined(_MSC_VER) && _MSC_VER >= 1911
21
# define RB_UNUSED_VAR(x) x [[maybe_unused]]
22
23
# elif defined(__has_cpp_attribute) && __has_cpp_attribute(maybe_unused)
24
# define RB_UNUSED_VAR(x) x [[maybe_unused]]
25
26
# elif defined(__has_c_attribute) && __has_c_attribute(maybe_unused)
27
# define RB_UNUSED_VAR(x) x [[maybe_unused]]
28
29
# elif defined(__GNUC__)
30
# define RB_UNUSED_VAR(x) x __attribute__ ((unused))
31
32
# else
33
# define RB_UNUSED_VAR(x) x
34
# endif
35
#endif
/* RB_UNUSED_VAR */
36
37
#if defined(_MSC_VER) && _MSC_VER >= 1310
38
# define HAVE___ASSUME
39
40
#elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1300
41
# define HAVE___ASSUME
42
#endif
43
44
#ifndef UNREACHABLE
45
# if __has_builtin(__builtin_unreachable)
46
# define UNREACHABLE __builtin_unreachable()
47
48
# elif defined(HAVE___ASSUME)
49
# define UNREACHABLE __assume(0)
50
51
# else
52
# define UNREACHABLE
/* unreachable */
53
# endif
54
#endif
/* UNREACHABLE */
55
56
/* bool */
57
58
#if defined(__bool_true_false_are_defined)
59
#
/* Take that. */
60
61
#elif defined(HAVE_STDBOOL_H)
62
# include <
stdbool.h
>
63
64
#else
65
typedef
unsigned
char
_Bool
;
66
# define bool _Bool
67
# define true ((_Bool)+1)
68
# define false ((_Bool)-1)
69
# define __bool_true_false_are_defined
70
#endif
71
72
/* abs */
73
74
#ifndef HAVE_LABS
75
static
inline
long
76
labs(
long
const
x)
77
{
78
if
(x < 0)
return
-x;
79
return
x;
80
}
81
#endif
82
83
#ifndef HAVE_LLABS
84
static
inline
LONG_LONG
85
llabs(
LONG_LONG
const
x)
86
{
87
if
(x < 0)
return
-x;
88
return
x;
89
}
90
#endif
91
92
#ifdef vabs
93
# undef vabs
94
#endif
95
#if SIZEOF_VALUE <= SIZEOF_INT
96
# define vabs abs
97
#elif SIZEOF_VALUE <= SIZEOF_LONG
98
# define vabs labs
99
#elif SIZEOF_VALUE <= SIZEOF_LONG_LONG
100
# define vabs llabs
101
#endif
102
103
/* finite */
104
105
#ifndef HAVE_FINITE
106
static
int
107
finite
(
double
)
108
{
109
return
!isnan(n) && !isinf(n);
110
}
111
#endif
112
113
#ifndef isfinite
114
# ifndef HAVE_ISFINITE
115
# define HAVE_ISFINITE 1
116
# define isfinite(x) finite(x)
117
# endif
118
#endif
119
120
/* dtoa */
121
char
*
BigDecimal_dtoa
(
double
d_,
int
mode,
int
ndigits,
int
*decpt,
int
*sign,
char
**rve);
122
123
/* rational */
124
125
#ifndef HAVE_RB_RATIONAL_NUM
126
static
inline
VALUE
127
rb_rational_num(
VALUE
rat)
128
{
129
#ifdef HAVE_TYPE_STRUCT_RRATIONAL
130
return
RRATIONAL
(rat)->num;
131
#else
132
return
rb_funcall
(rat,
rb_intern
(
"numerator"
), 0);
133
#endif
134
}
135
#endif
136
137
#ifndef HAVE_RB_RATIONAL_DEN
138
static
inline
VALUE
139
rb_rational_den(
VALUE
rat)
140
{
141
#ifdef HAVE_TYPE_STRUCT_RRATIONAL
142
return
RRATIONAL
(rat)->den;
143
#else
144
return
rb_funcall
(rat,
rb_intern
(
"denominator"
), 0);
145
#endif
146
}
147
#endif
148
149
/* complex */
150
151
#ifndef HAVE_RB_COMPLEX_REAL
152
static
inline
VALUE
153
rb_complex_real
(
VALUE
cmp)
154
{
155
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
156
return
RCOMPLEX
(cmp)->real;
157
#else
158
return
rb_funcall
(cmp,
rb_intern
(
"real"
), 0);
159
#endif
160
}
161
#endif
162
163
#ifndef HAVE_RB_COMPLEX_IMAG
164
static
inline
VALUE
165
rb_complex_imag
(
VALUE
cmp)
166
{
167
# ifdef HAVE_TYPE_STRUCT_RCOMPLEX
168
return
RCOMPLEX
(cmp)->imag;
169
# else
170
return
rb_funcall
(cmp,
rb_intern
(
"imag"
), 0);
171
# endif
172
}
173
#endif
174
175
/* array */
176
177
#ifndef FIX_CONST_VALUE_PTR
178
# if defined(__fcc__) || defined(__fcc_version) || \
179
defined(__FCC__) || defined(__FCC_VERSION)
180
/* workaround for old version of Fujitsu C Compiler (fcc) */
181
# define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x))
182
# else
183
# define FIX_CONST_VALUE_PTR(x) (x)
184
# endif
185
#endif
186
187
#ifndef HAVE_RB_ARRAY_CONST_PTR
188
static
inline
const
VALUE
*
189
rb_array_const_ptr(
VALUE
a)
190
{
191
return
FIX_CONST_VALUE_PTR
((
RBASIC
(a)->flags &
RARRAY_EMBED_FLAG
) ?
192
RARRAY
(a)->as.ary :
RARRAY
(a)->as.heap.ptr);
193
}
194
#endif
195
196
#ifndef RARRAY_CONST_PTR
197
# define RARRAY_CONST_PTR(a) rb_array_const_ptr(a)
198
#endif
199
200
#ifndef RARRAY_AREF
201
# define RARRAY_AREF(a, i) (RARRAY_CONST_PTR(a)[i])
202
#endif
203
204
/* symbol */
205
206
#ifndef HAVE_RB_SYM2STR
207
static
inline
VALUE
208
rb_sym2str(
VALUE
sym
)
209
{
210
return
rb_id2str
(
SYM2ID
(
sym
));
211
}
212
#endif
213
214
/* st */
215
216
#ifndef ST2FIX
217
# undef RB_ST2FIX
218
# define RB_ST2FIX(h) LONG2FIX((long)(h))
219
# define ST2FIX(h) RB_ST2FIX(h)
220
#endif
221
222
/* warning */
223
224
#if !defined(HAVE_RB_CATEGORY_WARN) || !defined(HAVE_CONST_RB_WARN_CATEGORY_DEPRECATED)
225
# define rb_category_warn(category, ...) rb_warn(__VA_ARGS__)
226
#endif
227
228
#if defined(__cplusplus)
229
#if 0
230
{
/* satisfy cc-mode */
231
#endif
232
}
/* extern "C" { */
233
#endif
234
235
#endif
/* MISSING_H */
rb_intern
ID rb_intern(const char *)
Definition:
symbol.c:784
RARRAY_EMBED_FLAG
@ RARRAY_EMBED_FLAG
Definition:
rarray.h:73
_Bool
unsigned char _Bool
Definition:
missing.h:65
RARRAY
#define RARRAY(obj)
Definition:
rarray.h:42
LONG_LONG
#define LONG_LONG
Definition:
long_long.h:34
stdbool.h
C99 shim for <stdbool.h>
rb_id2str
#define rb_id2str(id)
Definition:
vm_backtrace.c:31
RCOMPLEX
#define RCOMPLEX(obj)
Definition:
complex.h:20
math.h
Internal header for Math.
RRATIONAL
#define RRATIONAL(obj)
Definition:
rational.h:24
sym
#define sym(name)
Definition:
enumerator.c:4043
rb_complex_imag
VALUE rb_complex_imag(VALUE self)
Definition:
complex.c:746
finite
#define finite(x)
Definition:
missing.h:153
BigDecimal_dtoa
char * BigDecimal_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
VALUE
unsigned long VALUE
Definition:
value.h:38
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition:
vm_eval.c:1113
FIX_CONST_VALUE_PTR
#define FIX_CONST_VALUE_PTR(x)
Definition:
missing.h:183
rb_complex_real
VALUE rb_complex_real(VALUE self)
Definition:
complex.c:729
RBASIC
#define RBASIC(obj)
Definition:
rbasic.h:34
SYM2ID
#define SYM2ID
Definition:
symbol.h:45
Generated by
1.8.17