w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

utilnumber.h
Go to the documentation of this file.
1 #ifndef UTIL_NUMBER_H
2 #define UTIL_NUMBER_H
3 
4 #include <stddef.h> // for size_t
5 
6 #include "utilplat.h"
7 #include "utildecl.h"
8 
9 #if defined(__cplusplus) && defined(_MSC_VER)
10 // int*_t types are in standard in msvc++
11 #else
12 # include <stdint.h>
13 #endif
14 
15 /* 'long' isn't long for msvc64/mingw64, we need a type for machine word */
16 
17 #if defined(_WIN64) || defined(__MINGW32__)
18 # define INT64F "%I64d"
19 # define UINT64F "%I64u"
20 #else
21 # define INT64F "%lld"
22 # define UINT64F "%llu"
23 #endif
24 
25 #if defined(MSVC64)
26 # define INTLW_IS_INT64
27 # define intlw_t int64_t
28 # define uintlw_t uint64_t
29 # define INTLW(N) N##I64
30 # define UINTLW(N) N##UI64
31 # define INTLWF INT64F
32 # define UINTLWF UINT64F
33 #elif defined(__MINGW64__)
34 # define INTLW_IS_INT64
35 # define intlw_t int64_t
36 # define uintlw_t uint64_t
37 # define INTLW(N) N##LL
38 # define UINTLW(N) N##ULL
39 # define INTLWF INT64F
40 # define UINTLWF UINT64F
41 #else // 32bit or sane 64bit (LP64)
42 # define INTLW_IS_LONG
43 # define intlw_t long
44 # define uintlw_t unsigned long
45 # define INTLW(N) N##L
46 # define UINTLW(N) N##UL
47 # define INTLWF "%ld"
48 # define UINTLWF "%lu"
49 #endif
50 
51 // ssize_t is missing in MSVC, but defining it is risky; some environments (eg. python) typedefs ssize_t on its own way..
52 // #if defined(MSVC64)
53 // # define ssize_t int32_t
54 // #else
55 // # if defined(MSVC32)
56 // # define ssize_t int64_t
57 // # endif
58 // #endif
59 
60 /* basic constants */
61 
62 #define MAX_RADIX 36
63 #define MAX_INTEGER_DIGITS 65 /* 64-bit number in binary form plus '\0' */
64 #define MAX_ROMAN_DIGITS 128 /* to handle romannumeral of short int (up to 65 leading 'M') */
65 #define MAX_NUMBER_DIGITS 512
66 #define NUMBER_BUFFER_SIZE MAX_NUMBER_DIGITS
67 
68 #define base36_uc_alphabet "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
69 #define base36_lc_alphabet "0123456789abcdefghijklmnopqrstuvwxyz"
70 
71 #define base26_uc_alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
72 #define base26_lc_alphabet "abcdefghijklmnopqrstuvwxyz"
73 extern const int base26_lookup[];
74 
75 #define base36_lc_palindrome "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"
76 #define base36_uc_palindrome "ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
77 
78 extern const int base36_lookup[];
79 
80 #define base10_palindrome "9876543210123456789"
81 #define base10_alphabet "0123456789"
82 extern const int base10_lookup[];
83 
84 #define base16_uc_alphabet "0123456789ABCDEF"
85 #define base16_lc_alphabet "0123456789abcdef"
86 extern const int base16_lookup[];
87 
88 #define base16_uc_digit1(c) base16_uc_alphabet[(c)>>4]
89 #define base16_uc_digit2(c) base16_uc_alphabet[(c)&15]
90 #define base16_lc_digit1(c) base16_lc_alphabet[(c)>>4]
91 #define base16_lc_digit2(c) base16_lc_alphabet[(c)&15]
92 
93 #define base8_digit(c) ((unsigned)(c - '0') <= (unsigned)('7' - '0'))
94 #define base8_value(c) (base8_digit(c) ? (c) - '0' : -1)
95 
96 #define base10_digit(c) ((unsigned)(c - '0') <= (unsigned)('9' - '0'))
97 #define base10_value(c) (base10_lookup[(uint8_t)(c)])
98 
99 #define base16_digit(c) (base16_lookup[(uint8_t)(c)] >= 0)
100 #define base16_value(c) (base16_lookup[(uint8_t)(c)])
101 
102 #define base26_digit(c) (base26_lookup[(uint8_t)(c)] >= 0)
103 #define base26_value(c) (base26_lookup[(uint8_t)(c)])
104 
105 #define base36_digit(c) (base36_lookup[(uint8_t)(c)] >= 0)
106 #define base36_value(c) (base36_lookup[(uint8_t)(c)])
107 
108 //#define base_digit(c, radix) ((unsigned)(base36_lookup[c]) < (unsigned)(radix))
109 //#define base_value(c, radix) (base_digit(c, radix) ? base36_lookup[c] : -1)
110 
112 
113 /* integer from string; return a pointer to character next to the last digit */
114 
115 UTILAPI const char * string_to_int32 (const char *s, int32_t *number);
116 UTILAPI const char * string_to_slong (const char *s, long *number);
117 UTILAPI const char * string_to_int64 (const char *s, int64_t *number);
118 
119 UTILAPI const char * string_to_uint32 (const char *s, uint32_t *number);
120 UTILAPI const char * string_to_ulong (const char *s, unsigned long *number);
121 UTILAPI const char * string_to_usize (const char *s, size_t *number);
122 UTILAPI const char * string_to_uint64 (const char *s, uint64_t *number);
123 
124 UTILAPI const char * radix_to_int32 (const char *s, int32_t *number, int radix);
125 UTILAPI const char * radix_to_slong (const char *s, long *number, int radix);
126 UTILAPI const char * radix_to_int64 (const char *s, int64_t *number, int radix);
127 
128 UTILAPI const char * radix_to_uint32 (const char *s, uint32_t *number, int radix);
129 UTILAPI const char * radix_to_ulong (const char *s, unsigned long *number, int radix);
130 UTILAPI const char * radix_to_usize (const char *s, size_t *number, int radix);
131 UTILAPI const char * radix_to_uint64 (const char *s, uint64_t *number, int radix);
132 
133 UTILAPI const char * alpha_to_uint32 (const char *s, uint32_t *number);
134 UTILAPI const char * alpha_to_ulong (const char *s, unsigned long *number);
135 UTILAPI const char * alpha_to_usize (const char *s, size_t *number);
136 UTILAPI const char * alpha_to_uint64 (const char *s, uint64_t *number);
137 
138 /* integer to string */
139 
140 UTILAPI char * int32_as_string (int32_t number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
141 UTILAPI char * slong_as_string (long number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
142 UTILAPI char * int64_as_string (int64_t number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
143 
144 #define int32_to_string(number, psize) int32_as_string(number, util_number_buffer, psize)
145 #define slong_to_string(number, psize) slong_as_string(number, util_number_buffer, psize)
146 #define int64_to_string(number, psize) int64_as_string(number, util_number_buffer, psize)
147 
148 UTILAPI char * uint32_as_string (uint32_t number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
149 UTILAPI char * ulong_as_string (unsigned long number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
150 UTILAPI char * usize_as_string (size_t number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
151 UTILAPI char * uint64_as_string (uint64_t number, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
152 
153 #define uint32_to_string(number, psize) uint32_as_string(number, util_number_buffer, psize)
154 #define ulong_to_string(number, psize) ulong_as_string(number, util_number_buffer, psize)
155 #define usize_to_string(number, psize) usize_as_string(number, util_number_buffer, psize)
156 #define uint64_to_string(number, psize) uint64_as_string(number, util_number_buffer, psize)
157 
158 UTILAPI char * int32_as_radix (int32_t number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
159 UTILAPI char * slong_as_radix (long number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
160 UTILAPI char * int64_as_radix (int64_t number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
161 
162 #define int32_to_radix(number, radix, uc, psize) int32_as_radix(number, radix, uc, util_number_buffer, psize)
163 #define slong_to_radix(number, radix, uc, psize) slong_as_radix(number, radix, uc, util_number_buffer, psize)
164 #define int64_to_radix(number, radix, uc, psize) int64_as_radix(number, radix, uc, util_number_buffer, psize)
165 
166 UTILAPI char * uint32_as_radix (uint32_t number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
167 UTILAPI char * ulong_as_radix (unsigned long number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
168 UTILAPI char * usize_as_radix (size_t number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
169 UTILAPI char * uint64_as_radix (uint64_t number, int radix, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
170 
171 #define uint32_to_radix(number, radix, uc, psize) uint32_as_radix(number, radix, uc, util_number_buffer, psize)
172 #define ulong_to_radix(number, radix, uc, psize) ulong_as_radix(number, radix, uc, util_number_buffer, psize)
173 #define usize_to_radix(number, radix, uc, psize) usize_as_radix(number, radix, uc, util_number_buffer, psize)
174 #define uint64_to_radix(number, radix, uc, psize) uint64_as_radix(number, radix, uc, util_number_buffer, psize)
175 
176 UTILAPI char * uint32_as_alpha (uint32_t number, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
177 UTILAPI char * ulong_as_alpha (unsigned long number, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
178 UTILAPI char * usize_as_alpha (size_t number, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
179 UTILAPI char * uint64_as_alpha (uint64_t number, int uc, char ibuf[MAX_INTEGER_DIGITS], size_t *psize);
180 
181 #define uint32_to_alpha(number, uc, psize) uint32_as_alpha(number, uc, util_number_buffer, psize)
182 #define ulong_to_alpha(number, uc, psize) ulong_as_alpha(number, uc, util_number_buffer, psize)
183 #define usize_to_alpha(number, uc, psize) usize_as_alpha(number, uc, util_number_buffer, psize)
184 #define uint64_to_alpha(number, uc, psize) uint64_as_alpha(number, uc, util_number_buffer, psize)
185 
186 #if defined(INTLW_IS_INT64)
187 
188 # define string_to_intlw(s, number) string_to_int64(s, number)
189 # define string_to_uintlw(s, number) string_to_uint64(s, number)
190 
191 # define radix_to_intlw(s, number, radix) radix_to_int64(s, number, radix)
192 # define radix_to_uintlw(s, number, radix) radix_to_uint64(s, number, radix)
193 
194 # define alpha_to_uintlw(s, number) alpha_to_uint64(s, number)
195 
196 # define intlw_as_string(number, ibuf, psize) int64_as_string(number, ibuf, psize)
197 # define uintlw_as_string(number, ibuf, psize) uint64_as_string(number, ibuf, psize)
198 
199 # define intlw_to_string(number, psize) int64_to_string(number, psize)
200 # define uintlw_to_string(number, psize) uint64_to_string(number, psize)
201 
202 # define intlw_as_radix(number, radix, uc, ibuf, psize) int64_as_radix(number, radix, uc, ibuf, psize)
203 # define uintlw_as_radix(number, radix, uc, ibuf, psize) uint64_as_radix(number, radix, uc, ibuf, psize)
204 
205 # define intlw_to_radix(number, radix, uc, psize) int64_to_radix(number, radix, uc, psize)
206 # define uintlw_to_radix(number, radix, uc, psize) uint64_to_radix(number, radix, uc, psize)
207 
208 # define uintlw_as_alpha(number, uc, ibuf, psize) uint64_as_alpha(number, uc, ibuf, psize)
209 # define uintlw_to_alpha(number, uc, psize) uint64_to_alpha(number, uc, ibuf, psize)
210 
211 #elif defined(INTLW_IS_LONG)
212 
213 # define string_to_intlw(s, number) string_to_slong(s, number)
214 # define string_to_uintlw(s, number) string_to_ulong(s, number)
215 
216 # define radix_to_intlw(s, number, radix) radix_to_slong(s, number, radix)
217 # define radix_to_uintlw(s, number, radix) radix_to_ulong(s, number, radix)
218 
219 # define alpha_to_uintlw(s, number) alpha_to_ulong(s, number)
220 
221 # define intlw_as_string(number, ibuf, psize) slong_as_string(number, ibuf, psize)
222 # define uintlw_as_string(number, ibuf, psize) ulong_as_string(number, ibuf, psize)
223 
224 # define intlw_to_string(number, psize) slong_to_string(number, psize)
225 # define uintlw_to_string(number, psize) ulong_to_string(number, psize)
226 
227 # define intlw_as_radix(number, radix, uc, ibuf, psize) slong_as_radix(number, radix, uc, ibuf, psize)
228 # define uintlw_as_radix(number, radix, uc, ibuf, psize) ulong_as_radix(number, radix, uc, ibuf, psize)
229 
230 # define intlw_to_radix(number, radix, uc, psize) slong_to_radix(number, radix, uc, psize)
231 # define uintlw_to_radix(number, radix, uc, psize) ulong_to_radix(number, radix, uc, psize)
232 
233 # define uintlw_as_alpha(number, uc, ibuf, psize) ulong_as_alpha(number, uc, ibuf, psize)
234 # define uintlw_to_alpha(number, uc, psize) ulong_to_alpha(number, uc, ibuf, psize)
235 
236 #endif
237 
238 /* a..z, aa..zz, aaa..zzz (limited to uint16_t, valid for N <= buffer_size * 26) */
239 
240 UTILAPI const char * alphan_to_uint16 (const char *s, uint16_t *number);
241 UTILAPI char * uint16_as_alphan (uint16_t number, int uc, char ibuf[], size_t size, size_t *psize);
242 #define uint16_to_alphan(number, uc, psize) uint16_as_alphan(number, uc, util_number_buffer, NUMBER_BUFFER_SIZE, psize)
243 
244 /* roman numeral (limited to uint16_t) */
245 
246 UTILAPI const char * roman_to_uint16 (const char *s, uint16_t *number);
247 UTILAPI char * uint16_as_roman (uint16_t number, int uc, char ibuf[MAX_ROMAN_DIGITS], size_t *psize);
248 #define uint16_to_roman(number, uc, psize) uint16_as_roman(number, uc, util_number_buffer, psize)
249 
250 /* double/float to string */
251 
252 UTILAPI char * double_as_string (double number, int digits, char nbuf[MAX_NUMBER_DIGITS], size_t *psize);
253 #define double_to_string(number, digits, psize) double_as_string(number, digits, util_number_buffer, psize)
254 
255 UTILAPI char * float_as_string (float number, int digits, char nbuf[MAX_NUMBER_DIGITS], size_t *psize);
256 #define float_to_string(number, digits, psize) float_as_string(number, digits, util_number_buffer, psize)
257 
258 /* string to double/float */
259 
260 UTILAPI const char * string_to_double (const char *s, double *number);
261 UTILAPI const char * string_to_float (const char *s, float *number);
262 
263 /* convenience form accepting comma among a dot, with not exp notation (eg. pdf) */
264 
265 UTILAPI const char * convert_to_double (const char *s, double *number);
266 UTILAPI const char * convert_to_float (const char *s, float *number);
267 
268 /* binary data parsers helpers */
269 
270 #if 0 // masking gives more overactive warnings
271 #define get_number_byte1(n) ((n) & 0x000000ffu)
272 #define get_number_byte2(n) (((n) & 0x0000ff00u) >> 8)
273 #define get_number_byte3(n) (((n) & 0x00ff0000u) >> 16)
274 #define get_number_byte4(n) (((n) & 0xff000000u) >> 24)
275 #define get_number_byte5(n) (((n) & 0x000000ff00000000ull) >> 32)
276 #define get_number_byte6(n) (((n) & 0x0000ff0000000000ull) >> 40)
277 #define get_number_byte7(n) (((n) & 0x00ff000000000000ull) >> 48)
278 #define get_number_byte8(n) (((n) & 0xff00000000000000ull) >> 56)
279 #else
280 #define get_number_byte1(n) ((n) & 0xff)
281 #define get_number_byte2(n) (((n) >> 8) & 0xff)
282 #define get_number_byte3(n) (((n) >> 16) & 0xff)
283 #define get_number_byte4(n) (((n) >> 24) & 0xff)
284 #define get_number_byte5(n) (((n) >> 32) & 0xff)
285 #define get_number_byte6(n) (((n) >> 40) & 0xff)
286 #define get_number_byte7(n) (((n) >> 48) & 0xff)
287 #define get_number_byte8(n) (((n) >> 56) & 0xff)
288 #endif
289 
290 #define get_number_bytes_be1(n, b) (b[0] = (uint8_t)get_number_byte1(n))
291 #define get_number_bytes_be2(n, b) (b[0] = (uint8_t)get_number_byte2(n), b[1] = (uint8_t)get_number_byte1(n))
292 #define get_number_bytes_be3(n, b) (b[0] = (uint8_t)get_number_byte3(n), b[1] = (uint8_t)get_number_byte2(n), b[2] = (uint8_t)get_number_byte1(n))
293 #define get_number_bytes_be4(n, b) (b[0] = (uint8_t)get_number_byte4(n), b[1] = (uint8_t)get_number_byte3(n), b[2] = (uint8_t)get_number_byte2(n), b[3] = (uint8_t)get_number_byte1(n))
294 
295 #define get_number_bytes_be5(n, b) (b[0] = (uint8_t)get_number_byte5(n), b[1] = (uint8_t)get_number_byte4(n), b[2] = (uint8_t)get_number_byte3(n), b[3] = (uint8_t)get_number_byte2(n), \
296  b[4] = (uint8_t)get_number_byte1(n))
297 #define get_number_bytes_be6(n, b) (b[0] = (uint8_t)get_number_byte6(n), b[1] = (uint8_t)get_number_byte5(n), b[2] = (uint8_t)get_number_byte4(n), b[3] = (uint8_t)get_number_byte3(n), \
298  b[4] = (uint8_t)get_number_byte2(n), b[5] = (uint8_t)get_number_byte1(n))
299 #define get_number_bytes_be7(n, b) (b[0] = (uint8_t)get_number_byte7(n), b[1] = (uint8_t)get_number_byte6(n), b[2] = (uint8_t)get_number_byte5(n), b[3] = (uint8_t)get_number_byte4(n), \
300  b[4] = (uint8_t)get_number_byte3(n), b[5] = (uint8_t)get_number_byte2(n), b[6] = (uint8_t)get_number_byte1(n))
301 #define get_number_bytes_be8(n, b) (b[0] = (uint8_t)get_number_byte8(n), b[1] = (uint8_t)get_number_byte7(n), b[2] = (uint8_t)get_number_byte6(n), b[3] = (uint8_t)get_number_byte5(n), \
302  b[4] = (uint8_t)get_number_byte4(n), b[5] = (uint8_t)get_number_byte3(n), b[6] = (uint8_t)get_number_byte2(n), b[7] = (uint8_t)get_number_byte1(n))
303 
304 #define read_uint16be_as(s, int_type) ((int_type)((s[0]<<8)|s[1]))
305 #define read_uint32be_as(s, int_type) ((int_type)((s[0]<<24)|(s[1]<<16)|(s[2]<<8)|s[3]))
306 
307 #define read_uint16le_as(s, int_type) ((int_type)((s[1]<<8)|s[0]))
308 #define read_uint32le_as(s, int_type) ((int_type)((s[3]<<24)|(s[2]<<16)|(s[1]<<8)|s[0]))
309 
310 #define read_uint16_native(s) (*((uint16_t *)(s)))
311 #define read_uint32_native(s) (*((uint32_t *)(s)))
312 #define read_int16_native(s) (*((int16_t *)(s)))
313 #define read_int32_native(s) (*((int32_t *)(s)))
314 
315 #define scan_uint16be_as(s, int_type) (s += 2, (int_type)((s[-2]<<8)|s[-1]))
316 #define scan_uint32be_as(s, int_type) (s += 4, (int_type)((s[-4]<<24)|(s[-3]<<16)|(s[-2]<<8)|s[-1]))
317 
318 #define scan_uint16le_as(s, int_type) (s += 2, (int_type)((s[-1]<<8)|s[-2]))
319 #define scan_uint32le_as(s, int_type) (s += 4, (int_type)((s[-1]<<24)|(s[-2]<<16)|(s[-3]<<8)|s[-4]))
320 
321 #define scan_uint16_native(s) (s += 2, read_uint16_native(s-2))
322 #define scan_uint32_native(s) (s += 4, read_uint32_native(s-4))
323 #define scan_int16_native(s) (s += 2, read_int16_native(s-2))
324 #define scan_int32_native(s) (s += 4, read_int32_native(s-4))
325 
326 #define read_fixed16_16_as(s, float_type) (((float_type)read_uint32be_as(s, signed int))/(1<<16))
327 #define read_fixed2_14_as(s, float_type) (((float_type)read_uint16be_as(s, signed short))/(1<<14))
328 
329 #define scan_fixed16_16_as(s, float_type) (((float_type)scan_uint32be_as(s, signed int))/(1<<16))
330 #define scan_fixed2_14_as(s, float_type) (((float_type)scan_uint16be_as(s, signed short))/(1<<14))
331 
332 /* internal procedures */
333 
334 #define _scan_sign(c, sign, next) \
335  do { if (c == '-') { sign = 1; c = next; } else if (c == '+') { sign = 0; c = next; } else sign = 0; } while (0)
336 
337 #define integer_multiplied10(number) (((number) << 1) + ((number) << 3))
338 
339 #define _scan_integer(c, number, next) \
340  for (number = 0; base10_digit(c); number = integer_multiplied10(number) + (c - '0'), c = next)
341 #define _scan_radix(c, number, radix, next) \
342  for (number = 0; (c = base36_value(c)) >= 0 && c < radix; number = number * radix + c, c = next)
343 
344 #define _read_integer(c, number, next) \
345  for (number = c - '0', c = next; base10_digit(c); number = integer_multiplied10(number) + (c - '0'), c = next)
346 #define _read_radix(c, number, radix, next) \
347  for (number = c - '0', c = next; (c = base36_value(c)) >= 0 && c < radix; number = number * radix + c, c = next)
348 
349 /* rationals */
350 
351 #define _scan_decimal(c, number, next) \
352  for (number = 0; base10_digit(c); number = number*10 + (c - '0'), c = next)
353 #define _scan_fraction(c, number, exponent10, next) \
354  for (exponent10 = 0; base10_digit(c); --exponent10, number = number*10 + (c - '0'), c = next)
355 
356 #define _scan_exponent10(c, exponent10, next) \
357  do { \
358  int eexponent10, eexpsign; \
359  _scan_sign(c, eexpsign, next); \
360  _scan_integer(c, eexponent10, next); \
361  if (eexpsign) \
362  exponent10 -= eexponent10; \
363  else \
364  exponent10 += eexponent10; \
365  } while(0)
366 
367 #if 0
368 
369 // kept just for sentiment ;)
370 
371 extern const double double_binary_power10[];
372 extern const float float_binary_power10[];
373 extern const double double_binary_negpower10[];
374 extern const float float_binary_negpower10[];
375 
376 #define double_negative_exp10(number, exponent) \
377 { const double *bp10; int e = ((exponent) < 511 ? 511 : -(exponent)); \
378  for (bp10 = double_binary_negpower10; e > 0; e >>= 1, ++bp10) \
379  if (e & 1) number *= *bp10; }
380 
381 #define float_negative_exp10(number, exponent) \
382 { const float *bp10; int e = ((exponent) < 64 ? 64 : -(exponent)); \
383  for (bp10 = float_binary_negpower10; e > 0; e >>= 1, ++bp10) \
384  if (e & 1) number *= *bp10; }
385 
386 #define double_positive_exp10(number, exponent) \
387 { const double *bp10; int e = ((exponent) > 511 ? 511 : (exponent)); \
388  for (bp10 = double_binary_power10; e > 0; e >>= 1, ++bp10) \
389  if (e & 1) number *= *bp10; }
390 
391 #define float_positive_exp10(number, exponent) \
392 { const float *bp10; int e = ((exponent) > 64 ? 64 : (exponent)); \
393  for (bp10 = double_binary_power10; e > 0; e >>= 1, ++bp10) \
394  if (e & 1) number *= *bp10; }
395 
396 #define double_exp10(number, exponent) \
397  if ((exponent) < 0) double_negative_exp10(number, exponent) else if ((exponent) > 0) double_positive_exp10(number, exponent)
398 
399 #define float_exp10(number, exponent) \
400  if ((exponent) < 0) float_negative_exp10(number, exponent) else if ((exponent) > 0) float_positive_exp10(number, exponent)
401 
402 #else
403 
404 extern const double double_decimal_power10[];
405 extern const float float_decimal_power10[];
406 extern const double double_decimal_negpower10[];
407 extern const float float_decimal_negpower10[];
408 
409 #define double_negative_exp10(number, exponent) ((number) *= double_decimal_negpower10[(exponent) < -308 ? 308 : -(exponent)])
410 #define double_positive_exp10(number, exponent) ((number) *= double_decimal_power10[(exponent) > 308 ? 308 : (exponent)])
411 
412 #define float_negative_exp10(number, exponent) ((number) *= float_decimal_negpower10[(exponent) < -38 ? 38 : -(exponent)])
413 #define float_positive_exp10(number, exponent) ((number) *= float_decimal_power10[(exponent) > 38 ? 38 : (exponent)])
414 
415 #define double_exp10(number, exponent) ((void)(((exponent) < 0 && double_negative_exp10(number, exponent)) || (((exponent) > 0 && double_positive_exp10(number, exponent)))))
416 #define float_exp10(number, exponent) ((void)(((exponent) < 0 && float_negative_exp10(number, exponent)) || (((exponent) > 0 && float_positive_exp10(number, exponent)))))
417 
418 #endif
419 
420 /* pretty common stuff */
421 
422 #define bytes_to_hex(input, size, output) bytes_to_hex_lc(input, size, output)
423 UTILAPI size_t bytes_to_hex_lc (const void *input, size_t size, uint8_t *output);
424 UTILAPI size_t bytes_to_hex_uc (const void *input, size_t size, uint8_t *output);
425 UTILAPI size_t hex_to_bytes (const void *input, size_t size, uint8_t *output);
426 UTILAPI void print_as_hex (const void *input, size_t bytes);
427 
428 #endif
static int radix
Definition: aptex.h:450
#define s
Definition: afcover.h:80
static char nbuf[100]
Definition: hpcdtoppm.c:135
unsigned short uint16_t
Definition: stdint.h:79
signed __int64 int64_t
Definition: stdint.h:89
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78
unsigned __int64 uint64_t
Definition: stdint.h:90
unsigned digits[12]
Definition: out_routines.c:255
static int size
Definition: ppmlabel.c:24
char ibuf[32000]
Definition: ps_tiny.c:177
static long bytes
Definition: psutil.c:35
#define UTILDEF
Definition: utildecl.h:25
#define UTILAPI
Definition: utildecl.h:24
#define MAX_NUMBER_DIGITS
Definition: utilnumber.h:65
const char * radix_to_usize(const char *s, size_t *number, int radix)
Definition: utilnumber.c:195
const char * radix_to_uint64(const char *s, uint64_t *number, int radix)
Definition: utilnumber.c:202
const int base36_lookup[]
Definition: utilnumber.c:68
const int base26_lookup[]
Definition: utilnumber.c:49
size_t hex_to_bytes(const void *input, size_t size, uint8_t *output)
Definition: utilnumber.c:1153
const char * string_to_int64(const char *s, int64_t *number)
Definition: utilnumber.c:117
char * int32_as_radix(int32_t number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:423
const char * radix_to_slong(const char *s, long *number, int radix)
Definition: utilnumber.c:163
char * uint16_as_roman(uint16_t number, int uc, char ibuf[128], size_t *psize)
Definition: utilnumber.c:606
const char * roman_to_uint16(const char *s, uint16_t *number)
Definition: utilnumber.c:223
const double double_decimal_negpower10[]
Definition: utilnumber.c:779
char * int64_as_string(int64_t number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:340
const char * alpha_to_uint64(const char *s, uint64_t *number)
Definition: utilnumber.c:499
char * usize_as_string(size_t number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:358
const float float_decimal_power10[]
Definition: utilnumber.c:772
const char * alphan_to_uint16(const char *s, uint16_t *number)
Definition: utilnumber.c:562
char * ulong_as_radix(unsigned long number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:455
const char * string_to_uint32(const char *s, uint32_t *number)
Definition: utilnumber.c:126
const int base16_lookup[]
Definition: utilnumber.c:30
const int base10_lookup[]
Definition: utilnumber.c:11
#define MAX_INTEGER_DIGITS
Definition: utilnumber.h:63
const float float_decimal_negpower10[]
Definition: utilnumber.c:813
#define MAX_ROMAN_DIGITS
Definition: utilnumber.h:64
char * slong_as_string(long number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:334
const char * string_to_uint64(const char *s, uint64_t *number)
Definition: utilnumber.c:147
char * uint32_as_radix(uint32_t number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:449
char util_number_buffer[512]
Definition: utilnumber.c:89
char * uint32_as_alpha(uint32_t number, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:526
char * int32_as_string(int32_t number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:328
char * uint32_as_string(uint32_t number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:346
const char * radix_to_ulong(const char *s, unsigned long *number, int radix)
Definition: utilnumber.c:188
char * ulong_as_alpha(unsigned long number, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:532
const char * radix_to_uint32(const char *s, uint32_t *number, int radix)
Definition: utilnumber.c:181
char * double_as_string(double number, int digits, char nbuf[512], size_t *psize)
Definition: utilnumber.c:979
size_t bytes_to_hex_lc(const void *input, size_t size, uint8_t *output)
Definition: utilnumber.c:1127
char * usize_as_alpha(size_t number, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:538
const char * radix_to_int32(const char *s, int32_t *number, int radix)
Definition: utilnumber.c:154
const char * string_to_double(const char *s, double *number)
Definition: utilnumber.c:1045
const char * alpha_to_usize(const char *s, size_t *number)
Definition: utilnumber.c:492
const char * alpha_to_uint32(const char *s, uint32_t *number)
Definition: utilnumber.c:478
char * usize_as_radix(size_t number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:461
const char * convert_to_float(const char *s, float *number)
Definition: utilnumber.c:1108
void print_as_hex(const void *input, size_t bytes)
Definition: utilnumber.c:1172
const double double_decimal_power10[]
Definition: utilnumber.c:738
const char * string_to_slong(const char *s, long *number)
Definition: utilnumber.c:108
char * uint64_as_string(uint64_t number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:364
char * uint16_as_alphan(uint16_t number, int uc, char ibuf[], size_t size, size_t *psize)
Definition: utilnumber.c:593
char * uint64_as_alpha(uint64_t number, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:544
const char * alpha_to_ulong(const char *s, unsigned long *number)
Definition: utilnumber.c:485
char * uint64_as_radix(uint64_t number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:467
char * ulong_as_string(unsigned long number, char ibuf[65], size_t *psize)
Definition: utilnumber.c:352
char * slong_as_radix(long number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:429
const char * string_to_int32(const char *s, int32_t *number)
Definition: utilnumber.c:99
char * float_as_string(float number, int digits, char nbuf[512], size_t *psize)
Definition: utilnumber.c:1010
const char * convert_to_double(const char *s, double *number)
Definition: utilnumber.c:1091
const char * string_to_usize(const char *s, size_t *number)
Definition: utilnumber.c:140
#define NUMBER_BUFFER_SIZE
Definition: utilnumber.h:66
const char * radix_to_int64(const char *s, int64_t *number, int radix)
Definition: utilnumber.c:172
size_t bytes_to_hex_uc(const void *input, size_t size, uint8_t *output)
Definition: utilnumber.c:1140
const char * string_to_ulong(const char *s, unsigned long *number)
Definition: utilnumber.c:133
const char * string_to_float(const char *s, float *number)
Definition: utilnumber.c:1067
char * int64_as_radix(int64_t number, int radix, int uc, char ibuf[65], size_t *psize)
Definition: utilnumber.c:443
Definition: execute.c:108
Definition: output.h:18