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/168/head
PhysicistJohn 3 months ago committed by erikkaashoek
parent d12696ddd6
commit 10abaf42a7

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

Loading…
Cancel
Save

Powered by TurnKey Linux.