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