… | |
… | |
948 | } |
948 | } |
949 | |
949 | |
950 | /*******************************************************************************/ |
950 | /*******************************************************************************/ |
951 | /* fast integer to ascii */ |
951 | /* fast integer to ascii */ |
952 | |
952 | |
|
|
953 | /* |
|
|
954 | * This code is pretty complicated because it is general. The idea behind it, |
|
|
955 | * however, is pretty simple: first, the number is multiplied with a scaling |
|
|
956 | * factor (2**bits / 10**(digits-1)) to convert nthe integer into a fixed-point |
|
|
957 | * number with the first digit in the upper bits. |
|
|
958 | * Then this digit is converted to text and masked out. The resulting number |
|
|
959 | * is then multiplied by 10, by multiplying the fixed point representation |
|
|
960 | * by 5 and shifting the (binary) decimal point one to the right, so a 4.28 |
|
|
961 | * format becomes 5.27, 6.26 and so on. |
|
|
962 | * The rest involves only advancing the pointer if we already generated a |
|
|
963 | * non-zero digit, so leading zeroes are overwritten. |
|
|
964 | */ |
|
|
965 | |
953 | // simply return a mask with "bits" bits set |
966 | // simply return a mask with "bits" bits set |
954 | #define ecb_i2a_mask(type,bits) ((((type)1) << (bits)) - 1) |
967 | #define ecb_i2a_mask(type,bits) ((((type)1) << (bits)) - 1) |
955 | |
968 | |
956 | // oputput a single digit. maskvalue is 10**digitidx |
969 | // oputput a single digit. maskvalue is 10**digitidx |
957 | #define ecb_i2a_digit(type,bits,digitmask,maskvalue,digitidx) \ |
970 | #define ecb_i2a_digit(type,bits,digitmask,maskvalue,digitidx) \ |