Tinkering bit locker misrenders numbers greater than 999

Issue #3572 resolved
Evan Balster created an issue

The tinkering screen doesn’t properly display numbers >= 1000. It displays the first three digits, so that a player with 1234 <B> bits will instead see “123”.

Yes, I’ve been playing too long.

Just for giggles, here’s a trick I use to fit arbitrary values into 4 characters, with 3 significant digits.

std::ostream& perilymph_calibrator::operator<<(std::ostream &out, Print_3SD d)
{
    size_t sig = d.n * 100, i = 0;
    for (; i < 5; ++i, sig /= 1000) if (sig < 100'000 || i == 4) break;

    const char *units = ".kmbtq";
    char unit = units[i];

    if      (sig <  1000) /* 1k23 */ out << (sig/100) << unit << ((sig/10)%10) << (sig%10);
    else if (sig < 10000) /* 12k3 */ out << (sig/100) << unit << ((sig/10)%10);
    else                  /* 123k */ out << (sig/100) << unit;

    return out;
}

Comments (4)

  1. Log in to comment