static void digitize(dec64_string_state state) { int64 coefficient; int digit; int place; coefficient = dec64_coefficient(state->number); if (coefficient < 0) { coefficient = -coefficient; } state->nr_digits = 0; state->nr_zeros = 0; for (place = 16; place >= 0; place -= 1) { digit = (int)(coefficient / power[place]); state->digits[state->nr_digits] = digit + '0'; if (digit == 0) { if (state->nr_digits != 0) { state->nr_digits += 1; } state->nr_zeros += 1; } else { state->nr_digits += 1; state->nr_zeros = 0; } coefficient -= digit * power[place]; } }
void print_dec64(dec64 number) { int64 exponent = dec64_exponent(number); int64 coefficient = dec64_coefficient(number); printf("%20lli", coefficient); if (exponent == -128) { printf(" nan"); } else if (exponent != 0) { printf("e%-+4lli", exponent); } }