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); } }
static void scientific(dec64_string_state state) { int64 exponent = dec64_exponent(state->number) + state->nr_digits; int nr_digits = (state->nr_digits - state->nr_zeros); int at = 1; emit_at(state, 0); if (at < nr_digits) { emit_decimal_point(state); emit_digits(state, 1, nr_digits); } emit_exponent(state, exponent - 1); }
static void engineering(dec64_string_state state) { int64 exponent = dec64_exponent(state->number) + state->nr_digits; int to = state->nr_digits - state->nr_zeros; int fudge = (int)exponent % 3; if (fudge <= 0) { fudge += 3; } emit_digits(state, 0, fudge); if (fudge < to) { emit_decimal_point(state); emit_digits(state, fudge, to); } emit_exponent(state, exponent - fudge); }
static void standard( dec64_string_state state ) { int from = 0; int to; int places; int sep = 0; int64 exponent = dec64_exponent(state->number); if (exponent >= 0) { to = state->nr_digits + (int)exponent; if (to + state->places > 20) { scientific(state); } else { emit_digits_separated(state, 0, to); if (state->places > 0) { emit_decimal_point(state); emit_digits(state, to, state->places + to); } } } else { from = (int)exponent + state->nr_digits; to = state->nr_digits - state->nr_zeros; if (from <= 0) { places = to - from; if (places > 18) { scientific(state); } else { emit(state, '0'); emit_decimal_point(state); if (places < state->places) { to = state->places + from; } emit_digits(state, from, to); } } else { emit_digits_separated(state, 0, from); emit_decimal_point(state); if (to - from < state->places) { to = state->places + from; } emit_digits(state, from, to); } } }