Handmade Hero » Forums » Game » minor bug/issue Day 328: Overly narrow assert in U64ToASCII
Ryan1729
1 posts
#10422 minor bug/issue Day 328: Overly narrow assert in U64ToASCII
10 months, 4 weeks ago Edited by on Jan. 18, 2017, 5:46 a.m. Reason: correct country

Right here on day 328 Casey implemented the U64ToASCII function as part of the printf replacement, and added the following assert to catch the case where there would be a divide by zero error since the loop in that function advances by diving Value by Base while Value != 0.

1
Assert(Base != 0);


However, if Base is 1 then the loop never stops since dividing by 1 doesn't do anything. The assert should probably be changed to something like the following.

1
Assert(Base > 1);


Side note, just after adding that assert, Casey wondered aloud whether there was such a thing as base zero. As far as I know there is not, but surprisingly negative bases are a thing! Some early Polish computers even used negabinary (base -2).