56 |
## Data Types. ## |
## Data Types. ## |
57 |
## ------------ ## |
## ------------ ## |
58 |
|
|
|
# b4_sint_type(MAX) |
|
|
# ----------------- |
|
|
# Return the smallest signed int type able to handle the number MAX. |
|
|
m4_define([b4_sint_type], |
|
|
[m4_if(m4_eval([$1 <= 127]), [1], [signed char], |
|
|
m4_eval([$1 <= 32767]), [1], [signed short], |
|
|
[signed int])]) |
|
|
|
|
|
|
|
|
# b4_uint_type(MAX) |
|
|
# ----------------- |
|
|
# Return the smallest unsigned int type able to handle the number MAX. |
|
|
m4_define([b4_uint_type], |
|
|
[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char], |
|
|
m4_eval([$1 <= 65535]), [1], [unsigned short], |
|
|
[unsigned int])]) |
|
59 |
|
|
60 |
|
# b4_ints_in(INT1, INT2, LOW, HIGH) |
61 |
|
# --------------------------------- |
62 |
|
# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. |
63 |
|
m4_define([b4_ints_in], |
64 |
|
[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) |
65 |
|
|
66 |
|
|
67 |
|
# b4_int_type(MIN, MAX) |
68 |
|
# --------------------- |
69 |
|
# Return the smallest int type able to handle numbers ranging from |
70 |
|
# MIN to MAX (included). |
71 |
|
m4_define([b4_int_type], |
72 |
|
[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], |
73 |
|
b4_ints_in($@, [-128], [128]), [1], [signed char], |
74 |
|
|
75 |
|
b4_ints_in($@, [0], [65535]), [1], [unsigned short], |
76 |
|
b4_ints_in($@, [-32768], [32767]), [1], [short], |
77 |
|
|
78 |
|
m4_eval([0 <= $1]), [1], [unsigned int], |
79 |
|
|
80 |
|
[int])]) |
81 |
|
|
82 |
|
# b4_int_type_for(NAME) |
83 |
|
# --------------------- |
84 |
|
# Return the smallest int type able to handle numbers ranging from |
85 |
|
# `NAME_min' to `NAME_max' (included). |
86 |
|
m4_define([b4_int_type_for], |
87 |
|
[b4_int_type($1_min, $1_max)]) |
88 |
|
|
89 |
|
|
90 |
## ------------------------- ## |
## ------------------------- ## |