Ruby: ext/rbconfig/sizeof/limits.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

limits.c
Go to the documentation of this file.
1#include <limits.h>
2#include "ruby/ruby.h"
3#ifdef HAVE_STDINT_H
4# include <stdint.h>
5#endif
6#ifdef HAVE_INTTYPES_H
7# include <stdint.h>
8#endif
9#ifdef HAVE_FLOAT_H
10# include <float.h>
11#endif
12
13void
14Init_limits(void)
15{
16 VALUE h = rb_hash_new();
17 rb_define_const(rb_define_module("RbConfig"), "LIMITS", h);
18
19#ifdef HAVE_LONG_LONG
20#ifndef ULLONG_MAX
21#define ULLONG_MAX ((unsigned LONG_LONG)LLONG_MAX*2+1)
22#endif
23#define MAX2NUM(name) ULL2NUM(name ## _MAX)
24#define MIN2NUM(name) LL2NUM(name ## _MIN)
25#else
26#define MAX2NUM(name) ULONG2NUM(name ## _MAX)
27#define MIN2NUM(name) LONG2NUM(name ## _MIN)
28#endif
29#define DEFINE(k, v) rb_hash_aset(h, rb_str_new_cstr(#k), v)
30
31#ifdef FIXNUM_MAX
32 DEFINE(FIXNUM_MAX, MAX2NUM(FIXNUM));
33#endif
34#ifdef FIXNUM_MIN
35 DEFINE(FIXNUM_MIN, MIN2NUM(FIXNUM));
36#endif
37#ifdef CHAR_MAX
38 DEFINE(CHAR_MAX, MAX2NUM(CHAR));
39#endif
40#ifdef CHAR_MIN
41 DEFINE(CHAR_MIN, MIN2NUM(CHAR));
42#endif
43#ifdef SCHAR_MAX
44 DEFINE(SCHAR_MAX, MAX2NUM(SCHAR));
45#endif
46#ifdef SCHAR_MIN
47 DEFINE(SCHAR_MIN, MIN2NUM(SCHAR));
48#endif
49#ifdef UCHAR_MAX
50 DEFINE(UCHAR_MAX, MAX2NUM(UCHAR));
51#endif
52#ifdef UCHAR_MIN
53 DEFINE(UCHAR_MIN, MIN2NUM(UCHAR));
54#endif
55#ifdef WCHAR_MAX
56 DEFINE(WCHAR_MAX, MAX2NUM(WCHAR));
57#endif
58#ifdef WCHAR_MIN
59 DEFINE(WCHAR_MIN, MIN2NUM(WCHAR));
60#endif
61#ifdef SHRT_MAX
62 DEFINE(SHRT_MAX, MAX2NUM(SHRT));
63#endif
64#ifdef SHRT_MIN
65 DEFINE(SHRT_MIN, MIN2NUM(SHRT));
66#endif
67#ifdef USHRT_MAX
68 DEFINE(USHRT_MAX, MAX2NUM(USHRT));
69#endif
70#ifdef USHRT_MIN
71 DEFINE(USHRT_MIN, MIN2NUM(USHRT));
72#endif
73#ifdef INT_MAX
74 DEFINE(INT_MAX, MAX2NUM(INT));
75#endif
76#ifdef INT_MIN
77 DEFINE(INT_MIN, MIN2NUM(INT));
78#endif
79#ifdef UINT_MAX
80 DEFINE(UINT_MAX, MAX2NUM(UINT));
81#endif
82#ifdef UINT_MIN
83 DEFINE(UINT_MIN, MIN2NUM(UINT));
84#endif
85#ifdef LONG_MAX
86 DEFINE(LONG_MAX, MAX2NUM(LONG));
87#endif
88#ifdef LONG_MIN
89 DEFINE(LONG_MIN, MIN2NUM(LONG));
90#endif
91#ifdef ULONG_MAX
92 DEFINE(ULONG_MAX, MAX2NUM(ULONG));
93#endif
94#ifdef ULONG_MIN
95 DEFINE(ULONG_MIN, MIN2NUM(ULONG));
96#endif
97#ifdef LLONG_MAX
98 DEFINE(LLONG_MAX, MAX2NUM(LLONG));
99#endif
100#ifdef LLONG_MIN
101 DEFINE(LLONG_MIN, MIN2NUM(LLONG));
102#endif
103#ifdef ULLONG_MAX
104 DEFINE(ULLONG_MAX, MAX2NUM(ULLONG));
105#endif
106#ifdef ULLONG_MIN
107 DEFINE(ULLONG_MIN, MIN2NUM(ULLONG));
108#endif
109#ifdef INT8_MAX
110 DEFINE(INT8_MAX, MAX2NUM(INT8));
111#endif
112#ifdef INT8_MIN
113 DEFINE(INT8_MIN, MIN2NUM(INT8));
114#endif
115#ifdef UINT8_MAX
116 DEFINE(UINT8_MAX, MAX2NUM(UINT8));
117#endif
118#ifdef UINT8_MIN
119 DEFINE(UINT8_MIN, MIN2NUM(UINT8));
120#endif
121#ifdef INT_LEAST8_MAX
122 DEFINE(INT_LEAST8_MAX, MAX2NUM(INT_LEAST8));
123#endif
124#ifdef INT_LEAST8_MIN
125 DEFINE(INT_LEAST8_MIN, MIN2NUM(INT_LEAST8));
126#endif
127#ifdef UINT_LEAST8_MAX
128 DEFINE(UINT_LEAST8_MAX, MAX2NUM(UINT_LEAST8));
129#endif
130#ifdef UINT_LEAST8_MIN
131 DEFINE(UINT_LEAST8_MIN, MIN2NUM(UINT_LEAST8));
132#endif
133#ifdef INT_FAST8_MAX
134 DEFINE(INT_FAST8_MAX, MAX2NUM(INT_FAST8));
135#endif
136#ifdef INT_FAST8_MIN
137 DEFINE(INT_FAST8_MIN, MIN2NUM(INT_FAST8));
138#endif
139#ifdef UINT_FAST8_MAX
140 DEFINE(UINT_FAST8_MAX, MAX2NUM(UINT_FAST8));
141#endif
142#ifdef UINT_FAST8_MIN
143 DEFINE(UINT_FAST8_MIN, MIN2NUM(UINT_FAST8));
144#endif
145#ifdef INT16_MAX
146 DEFINE(INT16_MAX, MAX2NUM(INT16));
147#endif
148#ifdef INT16_MIN
149 DEFINE(INT16_MIN, MIN2NUM(INT16));
150#endif
151#ifdef UINT16_MAX
152 DEFINE(UINT16_MAX, MAX2NUM(UINT16));
153#endif
154#ifdef UINT16_MIN
155 DEFINE(UINT16_MIN, MIN2NUM(UINT16));
156#endif
157#ifdef INT_LEAST16_MAX
158 DEFINE(INT_LEAST16_MAX, MAX2NUM(INT_LEAST16));
159#endif
160#ifdef INT_LEAST16_MIN
161 DEFINE(INT_LEAST16_MIN, MIN2NUM(INT_LEAST16));
162#endif
163#ifdef UINT_LEAST16_MAX
164 DEFINE(UINT_LEAST16_MAX, MAX2NUM(UINT_LEAST16));
165#endif
166#ifdef UINT_LEAST16_MIN
167 DEFINE(UINT_LEAST16_MIN, MIN2NUM(UINT_LEAST16));
168#endif
169#ifdef INT_FAST16_MAX
170 DEFINE(INT_FAST16_MAX, MAX2NUM(INT_FAST16));
171#endif
172#ifdef INT_FAST16_MIN
173 DEFINE(INT_FAST16_MIN, MIN2NUM(INT_FAST16));
174#endif
175#ifdef UINT_FAST16_MAX
176 DEFINE(UINT_FAST16_MAX, MAX2NUM(UINT_FAST16));
177#endif
178#ifdef UINT_FAST16_MIN
179 DEFINE(UINT_FAST16_MIN, MIN2NUM(UINT_FAST16));
180#endif
181#ifdef INT32_MAX
182 DEFINE(INT32_MAX, MAX2NUM(INT32));
183#endif
184#ifdef INT32_MIN
185 DEFINE(INT32_MIN, MIN2NUM(INT32));
186#endif
187#ifdef UINT32_MAX
188 DEFINE(UINT32_MAX, MAX2NUM(UINT32));
189#endif
190#ifdef UINT32_MIN
191 DEFINE(UINT32_MIN, MIN2NUM(UINT32));
192#endif
193#ifdef INT_LEAST32_MAX
194 DEFINE(INT_LEAST32_MAX, MAX2NUM(INT_LEAST32));
195#endif
196#ifdef INT_LEAST32_MIN
197 DEFINE(INT_LEAST32_MIN, MIN2NUM(INT_LEAST32));
198#endif
199#ifdef UINT_LEAST32_MAX
200 DEFINE(UINT_LEAST32_MAX, MAX2NUM(UINT_LEAST32));
201#endif
202#ifdef UINT_LEAST32_MIN
203 DEFINE(UINT_LEAST32_MIN, MIN2NUM(UINT_LEAST32));
204#endif
205#ifdef INT_FAST32_MAX
206 DEFINE(INT_FAST32_MAX, MAX2NUM(INT_FAST32));
207#endif
208#ifdef INT_FAST32_MIN
209 DEFINE(INT_FAST32_MIN, MIN2NUM(INT_FAST32));
210#endif
211#ifdef UINT_FAST32_MAX
212 DEFINE(UINT_FAST32_MAX, MAX2NUM(UINT_FAST32));
213#endif
214#ifdef UINT_FAST32_MIN
215 DEFINE(UINT_FAST32_MIN, MIN2NUM(UINT_FAST32));
216#endif
217#ifdef INT64_MAX
218 DEFINE(INT64_MAX, MAX2NUM(INT64));
219#endif
220#ifdef INT64_MIN
221 DEFINE(INT64_MIN, MIN2NUM(INT64));
222#endif
223#ifdef UINT64_MAX
224 DEFINE(UINT64_MAX, MAX2NUM(UINT64));
225#endif
226#ifdef UINT64_MIN
227 DEFINE(UINT64_MIN, MIN2NUM(UINT64));
228#endif
229#ifdef INT_LEAST64_MAX
230 DEFINE(INT_LEAST64_MAX, MAX2NUM(INT_LEAST64));
231#endif
232#ifdef INT_LEAST64_MIN
233 DEFINE(INT_LEAST64_MIN, MIN2NUM(INT_LEAST64));
234#endif
235#ifdef UINT_LEAST64_MAX
236 DEFINE(UINT_LEAST64_MAX, MAX2NUM(UINT_LEAST64));
237#endif
238#ifdef UINT_LEAST64_MIN
239 DEFINE(UINT_LEAST64_MIN, MIN2NUM(UINT_LEAST64));
240#endif
241#ifdef INT_FAST64_MAX
242 DEFINE(INT_FAST64_MAX, MAX2NUM(INT_FAST64));
243#endif
244#ifdef INT_FAST64_MIN
245 DEFINE(INT_FAST64_MIN, MIN2NUM(INT_FAST64));
246#endif
247#ifdef UINT_FAST64_MAX
248 DEFINE(UINT_FAST64_MAX, MAX2NUM(UINT_FAST64));
249#endif
250#ifdef UINT_FAST64_MIN
251 DEFINE(UINT_FAST64_MIN, MIN2NUM(UINT_FAST64));
252#endif
253#ifdef INT128_MAX
254 DEFINE(INT128_MAX, MAX2NUM(INT128));
255#endif
256#ifdef INT128_MIN
257 DEFINE(INT128_MIN, MIN2NUM(INT128));
258#endif
259#ifdef UINT128_MAX
260 DEFINE(UINT128_MAX, MAX2NUM(UINT128));
261#endif
262#ifdef UINT128_MIN
263 DEFINE(UINT128_MIN, MIN2NUM(UINT128));
264#endif
265#ifdef INTMAX_MAX
266 DEFINE(INTMAX_MAX, MAX2NUM(INTMAX));
267#endif
268#ifdef INTMAX_MIN
269 DEFINE(INTMAX_MIN, MIN2NUM(INTMAX));
270#endif
271#ifdef UINTMAX_MAX
272 DEFINE(UINTMAX_MAX, MAX2NUM(UINTMAX));
273#endif
274#ifdef UINTMAX_MIN
275 DEFINE(UINTMAX_MIN, MIN2NUM(UINTMAX));
276#endif
277#ifdef INTPTR_MAX
278 DEFINE(INTPTR_MAX, MAX2NUM(INTPTR));
279#endif
280#ifdef INTPTR_MIN
281 DEFINE(INTPTR_MIN, MIN2NUM(INTPTR));
282#endif
283#ifdef UINTPTR_MAX
284 DEFINE(UINTPTR_MAX, MAX2NUM(UINTPTR));
285#endif
286#ifdef UINTPTR_MIN
287 DEFINE(UINTPTR_MIN, MIN2NUM(UINTPTR));
288#endif
289#ifdef SSZIE_MAX
290 DEFINE(SSZIE_MAX, MAX2NUM(SSZIE));
291#endif
292#ifdef SSZIE_MIN
293 DEFINE(SSZIE_MIN, MIN2NUM(SSZIE));
294#endif
295#ifdef SIZE_MAX
296 DEFINE(SIZE_MAX, MAX2NUM(SIZE));
297#endif
298#ifdef SIZE_MIN
299 DEFINE(SIZE_MIN, MIN2NUM(SIZE));
300#endif
301#ifdef PTRDIFF_MAX
302 DEFINE(PTRDIFF_MAX, MAX2NUM(PTRDIFF));
303#endif
304#ifdef PTRDIFF_MIN
305 DEFINE(PTRDIFF_MIN, MIN2NUM(PTRDIFF));
306#endif
307
308#ifdef FLT_RADIX
309 DEFINE(FLT_RADIX, LONG2NUM(FLT_RADIX));
310#endif
311#ifdef FLT_ROUNDS
312 DEFINE(FLT_ROUNDS, LONG2NUM(FLT_ROUNDS));
313#endif
314#ifdef FLT_EVAL_METHOD
315 DEFINE(FLT_EVAL_METHOD, LONG2NUM(FLT_EVAL_METHOD));
316#endif
317#ifdef FLT_MANT_DIG
318 DEFINE(FLT_MANT_DIG, LONG2NUM(FLT_MANT_DIG));
319#endif
320#ifdef DBL_MANT_DIG
321 DEFINE(DBL_MANT_DIG, LONG2NUM(DBL_MANT_DIG));
322#endif
323#ifdef LDBL_MANT_DIG
324 DEFINE(LDBL_MANT_DIG, LONG2NUM(LDBL_MANT_DIG));
325#endif
326#ifdef FLT_DIG
327 DEFINE(FLT_DIG, LONG2NUM(FLT_DIG));
328#endif
329#ifdef DBL_DIG
330 DEFINE(DBL_DIG, LONG2NUM(DBL_DIG));
331#endif
332#ifdef LDBL_DIG
333 DEFINE(LDBL_DIG, LONG2NUM(LDBL_DIG));
334#endif
335#ifdef FLT_MIN_EXP
336 DEFINE(FLT_MIN_EXP, LONG2NUM(FLT_MIN_EXP));
337#endif
338#ifdef DBL_MIN_EXP
339 DEFINE(DBL_MIN_EXP, LONG2NUM(DBL_MIN_EXP));
340#endif
341#ifdef LDBL_MIN_EXP
342 DEFINE(LDBL_MIN_EXP, LONG2NUM(LDBL_MIN_EXP));
343#endif
344#ifdef FLT_MIN_10_EXP
345 DEFINE(FLT_MIN_10_EXP, LONG2NUM(FLT_MIN_10_EXP));
346#endif
347#ifdef DBL_MIN_10_EXP
348 DEFINE(DBL_MIN_10_EXP, LONG2NUM(DBL_MIN_10_EXP));
349#endif
350#ifdef LDBL_MIN_10_EXP
351 DEFINE(LDBL_MIN_10_EXP, LONG2NUM(LDBL_MIN_10_EXP));
352#endif
353#ifdef FLT_MAX_EXP
354 DEFINE(FLT_MAX_EXP, LONG2NUM(FLT_MAX_EXP));
355#endif
356#ifdef DBL_MAX_EXP
357 DEFINE(DBL_MAX_EXP, LONG2NUM(DBL_MAX_EXP));
358#endif
359#ifdef LDBL_MAX_EXP
360 DEFINE(LDBL_MAX_EXP, LONG2NUM(LDBL_MAX_EXP));
361#endif
362#ifdef FLT_MAX_10_EXP
363 DEFINE(FLT_MAX_10_EXP, LONG2NUM(FLT_MAX_10_EXP));
364#endif
365#ifdef DBL_MAX_10_EXP
366 DEFINE(DBL_MAX_10_EXP, LONG2NUM(DBL_MAX_10_EXP));
367#endif
368#ifdef LDBL_MAX_10_EXP
369 DEFINE(LDBL_MAX_10_EXP, LONG2NUM(LDBL_MAX_10_EXP));
370#endif
371#ifdef FLT_DECIMAL_DIG
372 DEFINE(FLT_DECIMAL_DIG, LONG2NUM(FLT_DECIMAL_DIG));
373#endif
374#ifdef DBL_DECIMAL_DIG
375 DEFINE(DBL_DECIMAL_DIG, LONG2NUM(DBL_DECIMAL_DIG));
376#endif
377#ifdef LDBL_DECIMAL_DIG
378 DEFINE(LDBL_DECIMAL_DIG, LONG2NUM(LDBL_DECIMAL_DIG));
379#endif
380#ifdef DECIMAL_DIG
381 DEFINE(DECIMAL_DIG, LONG2NUM(DECIMAL_DIG));
382#endif
383#ifdef FLT_HAS_SUBNORM
384 DEFINE(FLT_HAS_SUBNORM, LONG2NUM(FLT_HAS_SUBNORM));
385#endif
386#ifdef DBL_HAS_SUBNORM
387 DEFINE(DBL_HAS_SUBNORM, LONG2NUM(DBL_HAS_SUBNORM));
388#endif
389#ifdef LDBL_HAS_SUBNORM
390 DEFINE(LDBL_HAS_SUBNORM, LONG2NUM(LDBL_HAS_SUBNORM));
391#endif
392
393#ifdef FLT_MAX
394 DEFINE(FLT_MAX, DBL2NUM(FLT_MAX));
395#endif
396#ifdef DBL_MAX
397 DEFINE(DBL_MAX, DBL2NUM(DBL_MAX));
398#endif
399#ifdef FLT_EPSILON
400 DEFINE(FLT_EPSILON, DBL2NUM(FLT_EPSILON));
401#endif
402#ifdef DBL_EPSILON
403 DEFINE(DBL_EPSILON, DBL2NUM(DBL_EPSILON));
404#endif
405#ifdef FLT_MIN
406 DEFINE(FLT_MIN, DBL2NUM(FLT_MIN));
407#endif
408#ifdef DBL_MIN
409 DEFINE(DBL_MIN, DBL2NUM(DBL_MIN));
410#endif
411#ifdef FLT_TRUE_MIN
412 DEFINE(FLT_TRUE_MIN, DBL2NUM(FLT_TRUE_MIN));
413#endif
414#ifdef DBL_TRUE_MIN
415 DEFINE(DBL_TRUE_MIN, DBL2NUM(DBL_TRUE_MIN));
416#endif
417
418#undef DEFINE
419#undef MIN2NUM
420#undef MAX2NUM
421 OBJ_FREEZE(h);
422}
DBL_MANT_DIG
#define DBL_MANT_DIG
Definition: acosh.c:19
DBL2NUM
#define DBL2NUM
Definition: double.h:29
UINT16
unsigned short UINT16
Definition: ffi_common.h:97
UINT64
unsigned __int64 UINT64
Definition: ffi_common.h:102
UINT8
unsigned char UINT8
Definition: ffi_common.h:95
UINT32
unsigned int UINT32
Definition: ffi_common.h:99
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:871
OBJ_FREEZE
#define OBJ_FREEZE
Definition: fl_type.h:134
SIZE
#define SIZE
Definition: gun.c:76
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:1538
FIXNUM_MIN
#define FIXNUM_MIN
Definition: fixnum.h:27
FIXNUM_MAX
#define FIXNUM_MAX
Definition: fixnum.h:26
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:3150
Init_limits
void Init_limits(void)
Definition: limits.c:14
MIN2NUM
#define MIN2NUM(name)
DEFINE
#define DEFINE(k, v)
MAX2NUM
#define MAX2NUM(name)
limits.h
Historical shim for <limits.h>.
LLONG_MAX
#define LLONG_MAX
Definition: limits.h:55
SIZE_MAX
#define SIZE_MAX
Definition: limits.h:71
LONG_MAX
#define LONG_MAX
Definition: limits.h:36
SIZE_MIN
#define SIZE_MIN
Definition: limits.h:72
LONG_MIN
#define LONG_MIN
Definition: limits.h:40
LLONG_MIN
#define LLONG_MIN
Definition: limits.h:65
LONG2NUM
#define LONG2NUM
Definition: long.h:50
DBL_MIN_EXP
#define DBL_MIN_EXP
Definition: numeric.c:55
DBL_MAX_EXP
#define DBL_MAX_EXP
Definition: numeric.c:58
FLT_RADIX
#define FLT_RADIX
Definition: numeric.c:46
DBL_MIN_10_EXP
#define DBL_MIN_10_EXP
Definition: numeric.c:61
DBL_MAX_10_EXP
#define DBL_MAX_10_EXP
Definition: numeric.c:64
DBL_DIG
#define DBL_DIG
Definition: numeric.c:67
DBL_MIN
#define DBL_MIN
Definition: numeric.c:49
DBL_EPSILON
#define DBL_EPSILON
Definition: numeric.c:73
DBL_MAX
#define DBL_MAX
Definition: numeric.c:52
ruby.h
VALUE
unsigned long VALUE
Definition: value.h:38
INTPTR_MIN
#define INTPTR_MIN
Definition: win32.h:100
INTPTR_MAX
#define INTPTR_MAX
Definition: win32.h:98
UINTPTR_MAX
#define UINTPTR_MAX
Definition: win32.h:114