3 ms·
I'd also assume that Mult can lead to overflow very easily, and if I'm not wrong, the solution proposed also doesn't check for such overflow/wrap around. So I'
by xarope 3y ago
I'd also assume that Mult can lead to overflow very easily, and if I'm not wrong, the solution proposed also doesn't check for such overflow/wrap around.
So I'd also concur that someone who blindly copy-pasted a "+" and changed everything to "*", doesn't really understand the difference between + and *.
- csande17 3y agoIs there a difference, in this case? Addition can also overflow.
- xarope 3y agonot as dramatically as mult can. and besides, if addition overflows, then it behooves you to ensure your next implementation doesn't, otherwise you are just adding technical debt.
- xxs 3y agoYes, I mentioned in a sibling answer - the mul overflows much easier and detecting is much harder, hence it uses two registers in the CPU for the result. Detecting sub/add overflow is a single CPU flag.
- xxs 3y agoThat was my 1st thought. Traditionally the mul CPU instruction uses two registers for the result, as the expectation is that it overflows. Add/sub needs only a single overflow/signed flag. OTOH, it's 64bit and only unsigned, so yeah 64 bit gotta be enough for everyone (unlike 640KB mem)?