int dec64_to_string( dec64_string_state state, dec64 number, dec64_string_char string[] ) { /* dec64_to_string converts a dec64 number into a string. The caller provides the memory in which to deposit the string. The string must have sufficient capacity to hold 32 characters. If NULL is passed in as the string, then no characters will be deposited, but a character count will be returned. dec64_to_string returns the number of characters actually deposited in the string (not including the trailing \0). If the number is nan, then it returns 0 indicating an empty string. In standard mode, the number will be formatted conventionally unless it would require more than 17 digits, which would be due to excessive trailing zeros or zeros immediately after the decimal point. In that case scientific notation will be used instead. */ if (state == NULL || state->valid != confirmed) { return 0; } state->length = 0; state->string = string; if (dec64_is_any_nan(number) != DEC64_TRUE) { if (dec64_is_zero(number) == DEC64_TRUE) { emit(state, '0'); } else { if (number != state->number) { state->number = number; digitize(state); } if (number < 0) { emit(state, '-'); } switch (state->mode) { case engineering_mode: engineering(state); break; case scientific_mode: scientific(state); break; case standard_mode: standard(state); break; } } } emit_end(state); state->string = NULL; return state->length; }
void test_is_zero(dec64 first, dec64 expected, char * comment) { dec64 actual = dec64_is_zero(first); judge_unary(first, expected, actual, "is_zero", "z", comment); }