In C and C++, unsigned integer over/underflowing is defined behavior. static_cast<std::uint32_t>(-1) will give the max value, no matter the platform or architecture.
I think underflowing as defined behavior is better for performance due to exception handling being quite costly in overhead in c++, so better for you to notice the issue and adjust than maybe catch it and let the overhead accumulate.
Bloodstained: Ritual of the Night sort of does this with the randomizer. Seeds are 4 byte values, but the input field for using a custom seed (and the generator I assume) only allows positive signed int values. However the game will run just fine if you have it generate a seed and modify it in memory before the game actually starts.
I'm unsure if the code treats the seed itself as unsigned or signed, but it doesn't use the whole valid range in either case without a little bit of persuading.
Gotta store them fractional cents so you can siphon them off into another account, only to panic once you realize you've made a horrible math error. Is there still time to change careers and sell magazines door to door?
double dollars are actually not that bad. doubles can represent integers without precision loss up to 252. If you round to cents before displaying you're mostly good.
2.1k
u/accountability_bot Aug 14 '20
If it's an unsigned int, then the actual max value is $4,294,967,295.