1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25 #ifndef __G_TYPES_H__
26 #define __G_TYPES_H__
27
28 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29 #error "Only <glib.h> can be included directly."
30 #endif
31
32 #include <glibconfig.h>
33 #include <glib/gmacros.h>
34 #include <glib/gversionmacros.h>
35 #include <time.h>
36
37 G_BEGIN_DECLS
38
39 /* Provide type definitions for commonly used types.
40 * These are useful because a "gint8" can be adjusted
41 * to be 1 byte (8 bits) on all platforms. Similarly and
42 * more importantly, "gint32" can be adjusted to be
43 * 4 bytes (32 bits) on all platforms.
44 */
45
46 typedef char gchar;
47 typedef short gshort;
48 typedef long glong;
49 typedef int gint;
50 typedef gint gboolean;
51
52 typedef unsigned char guchar;
53 typedef unsigned short gushort;
54 typedef unsigned long gulong;
55 typedef unsigned int guint;
56
57 typedef float gfloat;
58 typedef double gdouble;
59
60 /* Define min and max constants for the fixed size numerical types */
61 /**
62 * G_MININT8: (value -128)
63 *
64 * The minimum value which can be held in a #gint8.
65 *
66 * Since: 2.4
67 */
68 #define G_MININT8 ((gint8) (-G_MAXINT8 - 1))
69 #define G_MAXINT8 ((gint8) 0x7f)
70 #define G_MAXUINT8 ((guint8) 0xff)
71
72 /**
73 * G_MININT16: (value -32768)
74 *
75 * The minimum value which can be held in a #gint16.
76 *
77 * Since: 2.4
78 */
79 #define G_MININT16 ((gint16) (-G_MAXINT16 - 1))
80 #define G_MAXINT16 ((gint16) 0x7fff)
81 #define G_MAXUINT16 ((guint16) 0xffff)
82
83 /**
84 * G_MININT32: (value -2147483648)
85 *
86 * The minimum value which can be held in a #gint32.
87 *
88 * Since: 2.4
89 */
90 #define G_MININT32 ((gint32) (-G_MAXINT32 - 1))
91 #define G_MAXINT32 ((gint32) 0x7fffffff)
92 #define G_MAXUINT32 ((guint32) 0xffffffff)
93
94 /**
95 * G_MININT64: (value -9223372036854775808)
96 *
97 * The minimum value which can be held in a #gint64.
98 */
99 #define G_MININT64 ((gint64) (-G_MAXINT64 - G_GINT64_CONSTANT(1)))
100 #define G_MAXINT64 G_GINT64_CONSTANT(0x7fffffffffffffff)
101 #define G_MAXUINT64 G_GUINT64_CONSTANT(0xffffffffffffffff)
102
103 typedef void* gpointer;
104 typedef const void *gconstpointer;
105
106 typedef gint (*GCompareFunc) (gconstpointer a,
107 gconstpointer b);
108 typedef gint (*GCompareDataFunc) (gconstpointer a,
109 gconstpointer b,
110 gpointer user_data);
111 typedef gboolean (*GEqualFunc) (gconstpointer a,
112 gconstpointer b);
113 typedef void (*GDestroyNotify) (gpointer data);
114 typedef void (*GFunc) (gpointer data,
115 gpointer user_data);
116 typedef guint (*GHashFunc) (gconstpointer key);
117 typedef void (*GHFunc) (gpointer key,
118 gpointer value,
119 gpointer user_data);
120
121 /**
122 * GCopyFunc:
123 * @src: (not nullable): A pointer to the data which should be copied
124 * @data: Additional data
125 *
126 * A function of this signature is used to copy the node data
127 * when doing a deep-copy of a tree.
128 *
129 * Returns: (not nullable): A pointer to the copy
130 *
131 * Since: 2.4
132 */
133 typedef gpointer (*GCopyFunc) (gconstpointer src,
134 gpointer data);
135 /**
136 * GFreeFunc:
137 * @data: a data pointer
138 *
139 * Declares a type of function which takes an arbitrary
140 * data pointer argument and has no return value. It is
141 * not currently used in GLib or GTK+.
142 */
143 typedef void (*GFreeFunc) (gpointer data);
144
145 /**
146 * GTranslateFunc:
147 * @str: the untranslated string
148 * @data: user data specified when installing the function, e.g.
149 * in g_option_group_set_translate_func()
150 *
151 * The type of functions which are used to translate user-visible
152 * strings, for <option>--help</option> output.
153 *
154 * Returns: a translation of the string for the current locale.
155 * The returned string is owned by GLib and must not be freed.
156 */
157 typedef const gchar * (*GTranslateFunc) (const gchar *str,
158 gpointer data);
159
160
161 /* Define some mathematical constants that aren't available
162 * symbolically in some strict ISO C implementations.
163 *
164 * Note that the large number of digits used in these definitions
165 * doesn't imply that GLib or current computers in general would be
166 * able to handle floating point numbers with an accuracy like this.
167 * It's mostly an exercise in futility and future proofing. For
168 * extended precision floating point support, look somewhere else
169 * than GLib.
170 */
171 #define G_E 2.7182818284590452353602874713526624977572470937000
172 #define G_LN2 0.69314718055994530941723212145817656807550013436026
173 #define G_LN10 2.3025850929940456840179914546843642076011014886288
174 #define G_PI 3.1415926535897932384626433832795028841971693993751
175 #define G_PI_2 1.5707963267948966192313216916397514420985846996876
176 #define G_PI_4 0.78539816339744830961566084581987572104929234984378
177 #define G_SQRT2 1.4142135623730950488016887242096980785696718753769
178
179 /* Portable endian checks and conversions
180 *
181 * glibconfig.h defines G_BYTE_ORDER which expands to one of
182 * the below macros.
183 */
184 #define G_LITTLE_ENDIAN 1234
185 #define G_BIG_ENDIAN 4321
186 #define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */
187
188
189 /* Basic bit swapping functions
190 */
191 #define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
192 (guint16) ((guint16) (val) >> 8) | \
193 (guint16) ((guint16) (val) << 8)))
194
195 #define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \
196 (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
197 (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \
198 (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \
199 (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
200
201 #define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \
202 (((guint64) (val) & \
203 (guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) | \
204 (((guint64) (val) & \
205 (guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) | \
206 (((guint64) (val) & \
207 (guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) | \
208 (((guint64) (val) & \
209 (guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) << 8) | \
210 (((guint64) (val) & \
211 (guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >> 8) | \
212 (((guint64) (val) & \
213 (guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) | \
214 (((guint64) (val) & \
215 (guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) | \
216 (((guint64) (val) & \
217 (guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56)))
218
219 /* Arch specific stuff for speed
220 */
221 #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
222
223 # if __GNUC__ >= 4 && defined (__GNUC_MINOR__) && __GNUC_MINOR__ >= 3
224 # define GUINT32_SWAP_LE_BE(val) ((guint32) __builtin_bswap32 ((guint32) (val)))
225 # define GUINT64_SWAP_LE_BE(val) ((guint64) __builtin_bswap64 ((guint64) (val)))
226 # endif
227
228 # if defined (__i386__)
229 # define GUINT16_SWAP_LE_BE_IA32(val) \
230 (G_GNUC_EXTENSION \
231 ({ guint16 __v, __x = ((guint16) (val)); \
232 if (__builtin_constant_p (__x)) \
233 __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \
234 else \
235 __asm__ ("rorw $8, %w0" \
236 : "=r" (__v) \
237 : "0" (__x) \
238 : "cc"); \
239 __v; }))
240 # if !defined (__i486__) && !defined (__i586__) \
241 && !defined (__pentium__) && !defined (__i686__) \
242 && !defined (__pentiumpro__) && !defined (__pentium4__)
243 # define GUINT32_SWAP_LE_BE_IA32(val) \
244 (G_GNUC_EXTENSION \
245 ({ guint32 __v, __x = ((guint32) (val)); \
246 if (__builtin_constant_p (__x)) \
247 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
248 else \
249 __asm__ ("rorw $8, %w0\n\t" \
250 "rorl $16, %0\n\t" \
251 "rorw $8, %w0" \
252 : "=r" (__v) \
253 : "0" (__x) \
254 : "cc"); \
255 __v; }))
256 # else /* 486 and higher has bswap */
257 # define GUINT32_SWAP_LE_BE_IA32(val) \
258 (G_GNUC_EXTENSION \
259 ({ guint32 __v, __x = ((guint32) (val)); \
260 if (__builtin_constant_p (__x)) \
261 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
262 else \
263 __asm__ ("bswap %0" \
264 : "=r" (__v) \
265 : "0" (__x)); \
266 __v; }))
267 # endif /* processor specific 32-bit stuff */
268 # define GUINT64_SWAP_LE_BE_IA32(val) \
269 (G_GNUC_EXTENSION \
270 ({ union { guint64 __ll; \
271 guint32 __l[2]; } __w, __r; \
272 __w.__ll = ((guint64) (val)); \
273 if (__builtin_constant_p (__w.__ll)) \
274 __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll); \
275 else \
276 { \
277 __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \
278 __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \
279 } \
280 __r.__ll; }))
281 /* Possibly just use the constant version and let gcc figure it out? */
282 # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val))
283 # ifndef GUINT32_SWAP_LE_BE
284 # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val))
285 # endif
286 # ifndef GUINT64_SWAP_LE_BE
287 # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val))
288 # endif
289 # elif defined (__ia64__)
290 # define GUINT16_SWAP_LE_BE_IA64(val) \
291 (G_GNUC_EXTENSION \
292 ({ guint16 __v, __x = ((guint16) (val)); \
293 if (__builtin_constant_p (__x)) \
294 __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \
295 else \
296 __asm__ __volatile__ ("shl %0 = %1, 48 ;;" \
297 "mux1 %0 = %0, @rev ;;" \
298 : "=r" (__v) \
299 : "r" (__x)); \
300 __v; }))
301 # define GUINT32_SWAP_LE_BE_IA64(val) \
302 (G_GNUC_EXTENSION \
303 ({ guint32 __v, __x = ((guint32) (val)); \
304 if (__builtin_constant_p (__x)) \
305 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
306 else \
307 __asm__ __volatile__ ("shl %0 = %1, 32 ;;" \
308 "mux1 %0 = %0, @rev ;;" \
309 : "=r" (__v) \
310 : "r" (__x)); \
311 __v; }))
312 # define GUINT64_SWAP_LE_BE_IA64(val) \
313 (G_GNUC_EXTENSION \
314 ({ guint64 __v, __x = ((guint64) (val)); \
315 if (__builtin_constant_p (__x)) \
316 __v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \
317 else \
318 __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \
319 : "=r" (__v) \
320 : "r" (__x)); \
321 __v; }))
322 # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA64 (val))
323 # ifndef GUINT32_SWAP_LE_BE
324 # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA64 (val))
325 # endif
326 # ifndef GUINT64_SWAP_LE_BE
327 # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA64 (val))
328 # endif
329 # elif defined (__x86_64__)
330 # define GUINT32_SWAP_LE_BE_X86_64(val) \
331 (G_GNUC_EXTENSION \
332 ({ guint32 __v, __x = ((guint32) (val)); \
333 if (__builtin_constant_p (__x)) \
334 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
335 else \
336 __asm__ ("bswapl %0" \
337 : "=r" (__v) \
338 : "0" (__x)); \
339 __v; }))
340 # define GUINT64_SWAP_LE_BE_X86_64(val) \
341 (G_GNUC_EXTENSION \
342 ({ guint64 __v, __x = ((guint64) (val)); \
343 if (__builtin_constant_p (__x)) \
344 __v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \
345 else \
346 __asm__ ("bswapq %0" \
347 : "=r" (__v) \
348 : "0" (__x)); \
349 __v; }))
350 /* gcc seems to figure out optimal code for this on its own */
351 # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
352 # ifndef GUINT32_SWAP_LE_BE
353 # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val))
354 # endif
355 # ifndef GUINT64_SWAP_LE_BE
356 # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val))
357 # endif
358 # else /* generic gcc */
359 # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
360 # ifndef GUINT32_SWAP_LE_BE
361 # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
362 # endif
363 # ifndef GUINT64_SWAP_LE_BE
364 # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
365 # endif
366 # endif
367 #else /* generic */
368 # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
369 # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
370 # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
371 #endif /* generic */
372
373 #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val))
374 #define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val))
375 #define GUINT32_SWAP_LE_PDP(val) ((guint32) ( \
376 (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
377 (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
378 #define GUINT32_SWAP_BE_PDP(val) ((guint32) ( \
379 (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
380 (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
381
382 /* The G*_TO_?E() macros are defined in glibconfig.h.
383 * The transformation is symmetric, so the FROM just maps to the TO.
384 */
385 #define GINT16_FROM_LE(val) (GINT16_TO_LE (val))
386 #define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val))
387 #define GINT16_FROM_BE(val) (GINT16_TO_BE (val))
388 #define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val))
389 #define GINT32_FROM_LE(val) (GINT32_TO_LE (val))
390 #define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val))
391 #define GINT32_FROM_BE(val) (GINT32_TO_BE (val))
392 #define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val))
393
394 #define GINT64_FROM_LE(val) (GINT64_TO_LE (val))
395 #define GUINT64_FROM_LE(val) (GUINT64_TO_LE (val))
396 #define GINT64_FROM_BE(val) (GINT64_TO_BE (val))
397 #define GUINT64_FROM_BE(val) (GUINT64_TO_BE (val))
398
399 #define GLONG_FROM_LE(val) (GLONG_TO_LE (val))
400 #define GULONG_FROM_LE(val) (GULONG_TO_LE (val))
401 #define GLONG_FROM_BE(val) (GLONG_TO_BE (val))
402 #define GULONG_FROM_BE(val) (GULONG_TO_BE (val))
403
404 #define GINT_FROM_LE(val) (GINT_TO_LE (val))
405 #define GUINT_FROM_LE(val) (GUINT_TO_LE (val))
406 #define GINT_FROM_BE(val) (GINT_TO_BE (val))
407 #define GUINT_FROM_BE(val) (GUINT_TO_BE (val))
408
409 #define GSIZE_FROM_LE(val) (GSIZE_TO_LE (val))
410 #define GSSIZE_FROM_LE(val) (GSSIZE_TO_LE (val))
411 #define GSIZE_FROM_BE(val) (GSIZE_TO_BE (val))
412 #define GSSIZE_FROM_BE(val) (GSSIZE_TO_BE (val))
413
414 /* Portable versions of host-network order stuff
415 */
416 #define g_ntohl(val) (GUINT32_FROM_BE (val))
417 #define g_ntohs(val) (GUINT16_FROM_BE (val))
418 #define g_htonl(val) (GUINT32_TO_BE (val))
419 #define g_htons(val) (GUINT16_TO_BE (val))
420
421 /* Overflow-checked unsigned integer arithmetic
422 */
423 #ifndef _GLIB_TEST_OVERFLOW_FALLBACK
424 /* https://bugzilla.gnome.org/show_bug.cgi?id=769104 */
425 #if __GNUC__ >= 5 && !defined(__INTEL_COMPILER)
426 #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
427 #elif g_macro__has_builtin(__builtin_uadd_overflow)
428 #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
429 #endif
430 #endif
431
432 #define g_uint_checked_add(dest, a, b) \
433 _GLIB_CHECKED_ADD_U32(dest, a, b)
434 #define g_uint_checked_mul(dest, a, b) \
435 _GLIB_CHECKED_MUL_U32(dest, a, b)
436
437 #define g_uint64_checked_add(dest, a, b) \
438 _GLIB_CHECKED_ADD_U64(dest, a, b)
439 #define g_uint64_checked_mul(dest, a, b) \
440 _GLIB_CHECKED_MUL_U64(dest, a, b)
441
442 #if GLIB_SIZEOF_SIZE_T == 8
443 #define g_size_checked_add(dest, a, b) \
444 _GLIB_CHECKED_ADD_U64(dest, a, b)
445 #define g_size_checked_mul(dest, a, b) \
446 _GLIB_CHECKED_MUL_U64(dest, a, b)
447 #else
448 #define g_size_checked_add(dest, a, b) \
449 _GLIB_CHECKED_ADD_U32(dest, a, b)
450 #define g_size_checked_mul(dest, a, b) \
451 _GLIB_CHECKED_MUL_U32(dest, a, b)
452 #endif
453
454 /* The names of the following inlines are private. Use the macro
455 * definitions above.
456 */
457 #ifdef _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
_GLIB_CHECKED_ADD_U32(guint32 * dest,guint32 a,guint32 b)458 static inline gboolean _GLIB_CHECKED_ADD_U32 (guint32 *dest, guint32 a, guint32 b) {
459 return !__builtin_uadd_overflow(a, b, dest); }
_GLIB_CHECKED_MUL_U32(guint32 * dest,guint32 a,guint32 b)460 static inline gboolean _GLIB_CHECKED_MUL_U32 (guint32 *dest, guint32 a, guint32 b) {
461 return !__builtin_umul_overflow(a, b, dest); }
_GLIB_CHECKED_ADD_U64(guint64 * dest,guint64 a,guint64 b)462 static inline gboolean _GLIB_CHECKED_ADD_U64 (guint64 *dest, guint64 a, guint64 b) {
463 G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
464 return !__builtin_uaddll_overflow(a, b, (unsigned long long *) dest); }
_GLIB_CHECKED_MUL_U64(guint64 * dest,guint64 a,guint64 b)465 static inline gboolean _GLIB_CHECKED_MUL_U64 (guint64 *dest, guint64 a, guint64 b) {
466 return !__builtin_umulll_overflow(a, b, (unsigned long long *) dest); }
467 #else
_GLIB_CHECKED_ADD_U32(guint32 * dest,guint32 a,guint32 b)468 static inline gboolean _GLIB_CHECKED_ADD_U32 (guint32 *dest, guint32 a, guint32 b) {
469 *dest = a + b; return *dest >= a; }
_GLIB_CHECKED_MUL_U32(guint32 * dest,guint32 a,guint32 b)470 static inline gboolean _GLIB_CHECKED_MUL_U32 (guint32 *dest, guint32 a, guint32 b) {
471 *dest = a * b; return !a || *dest / a == b; }
_GLIB_CHECKED_ADD_U64(guint64 * dest,guint64 a,guint64 b)472 static inline gboolean _GLIB_CHECKED_ADD_U64 (guint64 *dest, guint64 a, guint64 b) {
473 *dest = a + b; return *dest >= a; }
_GLIB_CHECKED_MUL_U64(guint64 * dest,guint64 a,guint64 b)474 static inline gboolean _GLIB_CHECKED_MUL_U64 (guint64 *dest, guint64 a, guint64 b) {
475 *dest = a * b; return !a || *dest / a == b; }
476 #endif
477
478 /* IEEE Standard 754 Single Precision Storage Format (gfloat):
479 *
480 * 31 30 23 22 0
481 * +--------+---------------+---------------+
482 * | s 1bit | e[30:23] 8bit | f[22:0] 23bit |
483 * +--------+---------------+---------------+
484 * B0------------------->B1------->B2-->B3-->
485 *
486 * IEEE Standard 754 Double Precision Storage Format (gdouble):
487 *
488 * 63 62 52 51 32 31 0
489 * +--------+----------------+----------------+ +---------------+
490 * | s 1bit | e[62:52] 11bit | f[51:32] 20bit | | f[31:0] 32bit |
491 * +--------+----------------+----------------+ +---------------+
492 * B0--------------->B1---------->B2--->B3----> B4->B5->B6->B7->
493 */
494 /* subtract from biased_exponent to form base2 exponent (normal numbers) */
495 typedef union _GDoubleIEEE754 GDoubleIEEE754;
496 typedef union _GFloatIEEE754 GFloatIEEE754;
497 #define G_IEEE754_FLOAT_BIAS (127)
498 #define G_IEEE754_DOUBLE_BIAS (1023)
499 /* multiply with base2 exponent to get base10 exponent (normal numbers) */
500 #define G_LOG_2_BASE_10 (0.30102999566398119521)
501 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
502 union _GFloatIEEE754
503 {
504 gfloat v_float;
505 struct {
506 guint mantissa : 23;
507 guint biased_exponent : 8;
508 guint sign : 1;
509 } mpn;
510 };
511 union _GDoubleIEEE754
512 {
513 gdouble v_double;
514 struct {
515 guint mantissa_low : 32;
516 guint mantissa_high : 20;
517 guint biased_exponent : 11;
518 guint sign : 1;
519 } mpn;
520 };
521 #elif G_BYTE_ORDER == G_BIG_ENDIAN
522 union _GFloatIEEE754
523 {
524 gfloat v_float;
525 struct {
526 guint sign : 1;
527 guint biased_exponent : 8;
528 guint mantissa : 23;
529 } mpn;
530 };
531 union _GDoubleIEEE754
532 {
533 gdouble v_double;
534 struct {
535 guint sign : 1;
536 guint biased_exponent : 11;
537 guint mantissa_high : 20;
538 guint mantissa_low : 32;
539 } mpn;
540 };
541 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
542 #error unknown ENDIAN type
543 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
544
545 typedef struct _GTimeVal GTimeVal GLIB_DEPRECATED_TYPE_IN_2_62_FOR(GDateTime);
546
547 struct _GTimeVal
548 {
549 glong tv_sec;
550 glong tv_usec;
551 } GLIB_DEPRECATED_TYPE_IN_2_62_FOR(GDateTime);
552
553 typedef gint grefcount;
554 typedef gint gatomicrefcount; /* should be accessed only using atomics */
555
556 G_END_DECLS
557
558 /* We prefix variable declarations so they can
559 * properly get exported in Windows DLLs.
560 */
561 #ifndef GLIB_VAR
562 # ifdef G_PLATFORM_WIN32
563 # ifdef GLIB_STATIC_COMPILATION
564 # define GLIB_VAR extern
565 # else /* !GLIB_STATIC_COMPILATION */
566 # ifdef GLIB_COMPILATION
567 # ifdef DLL_EXPORT
568 # define GLIB_VAR extern __declspec(dllexport)
569 # else /* !DLL_EXPORT */
570 # define GLIB_VAR extern
571 # endif /* !DLL_EXPORT */
572 # else /* !GLIB_COMPILATION */
573 # define GLIB_VAR extern __declspec(dllimport)
574 # endif /* !GLIB_COMPILATION */
575 # endif /* !GLIB_STATIC_COMPILATION */
576 # else /* !G_PLATFORM_WIN32 */
577 # define GLIB_VAR _GLIB_EXTERN
578 # endif /* !G_PLATFORM_WIN32 */
579 #endif /* GLIB_VAR */
580
581 #endif /* __G_TYPES_H__ */
582