a68g-stddef.h
1 //! @file a68g-stddef.h
2 //! @author J. Marcel van der Veer
3
4 //! @section Copyright
5 //!
6 //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
7 //! Copyright 2001-2024 J. Marcel van der Veer [algol68g@xs4all.nl].
8
9 //! @section License
10 //!
11 //! This program is free software; you can redistribute it and/or modify it
12 //! under the terms of the GNU General Public License as published by the
13 //! Free Software Foundation; either version 3 of the License, or
14 //! (at your option) any later version.
15 //!
16 //! This program is distributed in the hope that it will be useful, but
17 //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 //! more details. You should have received a copy of the GNU General Public
20 //! License along with this program. If not, see [http://www.gnu.org/licenses/].
21
22 //! @section Synopsis
23 //!
24 //! Various standard definitions.
25
26 #if !defined (__A68G_STDDEF_H__)
27 #define __A68G_STDDEF_H__
28
29 #define DOUBLE_ACCURACY (A68_REAL_DIG - 1)
30
31 #define A68_BITS_WIDTH ((int) (1 + ceil (log ((REAL_T) A68_MAX_INT) / log ((REAL_T) 2))))
32 #define A68_INT_WIDTH ((int) (1 + floor (log ((REAL_T) A68_MAX_INT) / log ((REAL_T) 10))))
33 #define A68_LONG_INT_WIDTH (1 + A68_LONG_WIDTH)
34 #define A68_REF_SIZE (SIZE_ALIGNED (A68_REF))
35 #define A68_SOUND_BYTES(s) ((int) (BITS_PER_SAMPLE (s)) / 8 + (int) (BITS_PER_SAMPLE (s) % 8 == 0 ? 0 : 1))
36 #define A68_SOUND_DATA_SIZE(s) ((int) (NUM_SAMPLES (s)) * (int) (NUM_CHANNELS (s)) * (int) (A68_SOUND_BYTES (s)))
37 #define A68_UNION_SIZE (SIZE_ALIGNED (A68_UNION))
38
39 // Multi-precision parameters
40 #define A68_LONG_LONG_EXP_WIDTH (A68_EXP_WIDTH)
41 #define A68_LONG_LONG_INT_WIDTH (1 + A68_LONG_LONG_WIDTH)
42 #define A68_LONG_LONG_REAL_WIDTH ((long_mp_digits() - 1) * LOG_MP_RADIX)
43 #define A68_LONG_LONG_WIDTH (long_mp_digits() * LOG_MP_RADIX)
44
45 // Other WIDTHs
46 #define A68_BYTES_WIDTH 32
47 #define A68_LONG_BYTES_WIDTH 256
48 #define MAX_REAL_EXPO 511
49
50 #if (A68_LEVEL >= 3)
51
52 #define A68_REAL_WIDTH (A68_REAL_DIG)
53 #define A68_MAX_BITS (ULLONG_MAX)
54 #define A68_LONG_WIDTH (2 * A68_INT_WIDTH + 1)
55 #define A68_LONG_REAL_WIDTH (A68_DOUBLE_DIG - 1)
56 #define A68_EXP_WIDTH ((int) (1 + log10 ((REAL_T) A68_REAL_MAX_EXP)))
57 #define A68_LONG_EXP_WIDTH ((int) (1 + log10 ((REAL_T) A68_DOUBLE_MAX_EXP)))
58 #define A68_LONG_BITS_WIDTH (2 * A68_BITS_WIDTH)
59 #define D_SIGN 0x8000000000000000LL
60 #define NaN_MP ((MP_T *) NULL)
61 #define MP_RADIX 1000000000
62 #define LOG_MP_RADIX 9
63 #define MP_RADIX_Q MP_RADIX##q
64 #define DEFAULT_DOUBLE_DIGITS 4
65 #define LONG_MP_DIGITS DEFAULT_DOUBLE_DIGITS
66 #define LONG_LONG_MP_DIGITS width_to_mp_digits (4 * A68_REAL_DIG + A68_REAL_DIG / 2)
67 #define MAX_MP_EXPONENT 111111 // Arbitrary. Largest range is A68_MAX_INT / Log A68_MAX_INT / LOG_MP_RADIX
68 #define MAX_REPR_INT 9223372036854775808.0 // 2^63, max int in an extended double (no implicit bit, so 62-bit mantissa)
69 #define MAX_DOUBLE_EXPO 4932
70
71 #else // if (A68_LEVEL <= 2)
72
73 #define A68_REAL_WIDTH (A68_REAL_DIG)
74 #define A68_MAX_BITS (UINT_MAX)
75 #define A68_LONG_WIDTH (LONG_MP_DIGITS * LOG_MP_RADIX)
76 #define A68_LONG_REAL_WIDTH ((LONG_MP_DIGITS - 1) * LOG_MP_RADIX)
77 #define A68_EXP_WIDTH ((int) (1 + log10 ((REAL_T) A68_REAL_MAX_EXP)))
78 #define A68_LONG_EXP_WIDTH (A68_EXP_WIDTH)
79 #define D_SIGN 0x80000000L
80 #define MP_BITS_BITS 23
81 #define MP_BITS_RADIX 8388608 // Max power of two smaller than MP_RADIX
82 #define NaN_MP ((MP_T *) NULL)
83 #define MP_RADIX 10000000
84 #define MP_RADIX_Q MP_RADIX##q
85 #define LOG_MP_RADIX 7
86 #define DEFAULT_DOUBLE_DIGITS 6
87 #define LONG_MP_DIGITS DEFAULT_DOUBLE_DIGITS
88 #define LONG_LONG_MP_DIGITS width_to_mp_digits (4 * A68_REAL_DIG + A68_REAL_DIG / 2)
89 #define MAX_MP_EXPONENT 142857 // Arbitrary. Largest range is A68_MAX_INT / Log A68_MAX_INT / LOG_MP_RADIX
90 #define MAX_REPR_INT 9007199254740992.0 // 2^53, max int in a double
91
92 #endif
93
94 #endif
© 2002-2024 J.M. van der Veer (jmvdveer@xs4all.nl)
|