fix: normalize exact powers in scientific output

The compact scientific formatter emits its leading digit by adding the
normalized integer mantissa to '0'.  Its upper normalization loop stops at
exactly 10, however, so powers of ten use ':' (the character after '9') as
their leading digit.  For example, -100.0 becomes -:.000000e+01.

Keep the normalized mantissa below 10.  This preserves surrounding values
and renders exact powers with a valid leading digit and adjusted exponent.
pull/163/head
PhysicistJohn 1 week ago
parent c97938697b
commit ca5df0b598

@ -231,7 +231,7 @@ static char *etoa(char *p, float num, uint32_t precision) {
int exp = 0;
if (num == 0) { *p++ = '0'; return p; }
while (num < 10) { num *= 10.0; exp--; }
while (num > 10) { num /= 10.0; exp++; }
while (num >= 10) { num /= 10.0; exp++; }
*p++ = ((int)num) + '0'; num *=10.0;
*p++ = '.';
if (precision == 0) precision = 6;

Loading…
Cancel
Save

Powered by TurnKey Linux.