… | |
… | |
168 | |
168 | |
169 | =item ECB_64BIT_NATIVE |
169 | =item ECB_64BIT_NATIVE |
170 | |
170 | |
171 | Evaluates to a true value (suitable for both preprocessor and C code |
171 | Evaluates to a true value (suitable for both preprocessor and C code |
172 | testing) if 64 bit integer types on this architecture are evaluated |
172 | testing) if 64 bit integer types on this architecture are evaluated |
173 | "natively", that is, with similar speeds as 32 bit integerss. While 64 bit |
173 | "natively", that is, with similar speeds as 32 bit integers. While 64 bit |
174 | integer support is very common (and in fatc required by libecb), 32 bit |
174 | integer support is very common (and in fact required by libecb), 32 bit |
175 | cpus have to emulate operations on them, so you might want to avoid them. |
175 | cpus have to emulate operations on them, so you might want to avoid them. |
176 | |
176 | |
177 | =item ECB_AMD64, ECB_AMD64_X32 |
177 | =item ECB_AMD64, ECB_AMD64_X32 |
178 | |
178 | |
179 | These two macros are defined to C<1> on the x86_64/amd64 ABI and the X32 |
179 | These two macros are defined to C<1> on the x86_64/amd64 ABI and the X32 |
… | |
… | |
950 | =item char *ecb_i2a_u32 (char *ptr, uint32_t value) |
950 | =item char *ecb_i2a_u32 (char *ptr, uint32_t value) |
951 | |
951 | |
952 | Takes an C<uint32_t> I<value> and formats it as a decimal number starting |
952 | Takes an C<uint32_t> I<value> and formats it as a decimal number starting |
953 | at I<ptr>, using at most C<ECB_I2A_I32_DIGITS> characters. Returns a |
953 | at I<ptr>, using at most C<ECB_I2A_I32_DIGITS> characters. Returns a |
954 | pointer to just after the generated string, where you would normally put |
954 | pointer to just after the generated string, where you would normally put |
955 | the temrinating C<0> character. This function outputs the minimum number |
955 | the terminating C<0> character. This function outputs the minimum number |
956 | of digits. |
956 | of digits. |
957 | |
957 | |
958 | =item ECB_I2A_U32_DIGITS (=10) |
958 | =item ECB_I2A_U32_DIGITS (=10) |
959 | |
959 | |
960 | =item char *ecb_i2a_i32 (char *ptr, int32_t value) |
960 | =item char *ecb_i2a_i32 (char *ptr, int32_t value) |
… | |
… | |
980 | =back |
980 | =back |
981 | |
981 | |
982 | =head3 LOW-LEVEL API |
982 | =head3 LOW-LEVEL API |
983 | |
983 | |
984 | The functions above use a number of low-level APIs which have some strict |
984 | The functions above use a number of low-level APIs which have some strict |
985 | limitaitons, but cna be used as building blocks (study of C<ecb_i2a_i32> |
985 | limitations, but can be used as building blocks (study of C<ecb_i2a_i32> |
986 | and related cunctions is recommended). |
986 | and related functions is recommended). |
987 | |
987 | |
988 | There are three families of functions: functions that convert a number |
988 | There are three families of functions: functions that convert a number |
989 | to a fixed number of digits with leading zeroes (C<ecb_i2a_0N>, C<0> |
989 | to a fixed number of digits with leading zeroes (C<ecb_i2a_0N>, C<0> |
990 | for "leading zeroes"), functions that generate up to N digits, skipping |
990 | for "leading zeroes"), functions that generate up to N digits, skipping |
991 | leading zeroes (C<_N>), and functions that can generate more digits, but |
991 | leading zeroes (C<_N>), and functions that can generate more digits, but |
992 | the leading digit has limited range (C<_xN>). |
992 | the leading digit has limited range (C<_xN>). |
993 | |
993 | |
994 | None of the functions deal with negative numbera. |
994 | None of the functions deal with negative numbers. |
995 | |
995 | |
996 | Example: convert an IP address in an u32 into dotted-quad: |
996 | Example: convert an IP address in an u32 into dotted-quad: |
997 | |
997 | |
998 | uint32_t ip = 0x0a000164; // 10.0.1.100 |
998 | uint32_t ip = 0x0a000164; // 10.0.1.100 |
999 | char ips[3 * 4 + 3 + 1]; |
999 | char ips[3 * 4 + 3 + 1]; |
… | |
… | |
1062 | functions, but they can generate one digit more, as long as the number |
1062 | functions, but they can generate one digit more, as long as the number |
1063 | is within range, which is given by the symbols C<ECB_I2A_MAX_X5> (almost |
1063 | is within range, which is given by the symbols C<ECB_I2A_MAX_X5> (almost |
1064 | 16 bit range) and C<ECB_I2A_MAX_X10> (a bit more than 31 bit range), |
1064 | 16 bit range) and C<ECB_I2A_MAX_X10> (a bit more than 31 bit range), |
1065 | respectively. |
1065 | respectively. |
1066 | |
1066 | |
1067 | For example, the sigit part of a 32 bit signed integer just fits into the |
1067 | For example, the digit part of a 32 bit signed integer just fits into the |
1068 | C<ECB_I2A_MAX_X10> range, so while C<ecb_i2a_x10> cannot convert a 10 |
1068 | C<ECB_I2A_MAX_X10> range, so while C<ecb_i2a_x10> cannot convert a 10 |
1069 | digit number, it can convert all 32 bit signed numbers. Sadly, it's not |
1069 | digit number, it can convert all 32 bit signed numbers. Sadly, it's not |
1070 | good enough for 32 bit unsigned numbers. |
1070 | good enough for 32 bit unsigned numbers. |
1071 | |
1071 | |
1072 | =back |
1072 | =back |