MIPT-ILab/mipt-mips

Add method to print 128-bit integers in decimal format

pavelkryukov opened this issue · 5 comments

Currently 128 bit integers cannot be printed as decimal, only least significant 64 bits are exposed:

return out << "..." << narrow_cast<uint64>( value);

Your task is to implement or copy-paste 128-bit print along with unit tests.

I already did it in some contest, if printing it by two halves is relevant solution. Where should be the unit-test folder? I didn't find any tests for all of the hiders in infra folder.

What do you mean by 'printing by 2 halves'?

What do you mean by 'printing by 2 halves'?

Something like

void print128(uint128 number) {
    if (number <= UINT64_MAX) {
        print64( number);
    } else {
        uint128 leading  = number / 10000000000000000000
        uint64  following = number % 10000000000000000000
        print64( leading);
        print64( following);
    }
}

That's hexadecimal, it's simple. Decimal is tricky,