View Single Post
Old January 19, 2017, 20:01   #12
kandrc
Swordsman
 
Join Date: Dec 2007
Posts: 284
kandrc is on a distinguished road
Quote:
Originally Posted by Pondlife View Post
If both sides of that division are integer, you'll end up with integer division. That's rarely what you want (e.g. 10/3 = 3). I'd normally force something to be float or double, e.g:

final *= (100.0 + context->boost) / 100.0;

Note that I know nothing about the Angband source; so I may well be talking out of my backside. But I've been burnt by integer division in C before so I thought I'd mention it.
Floating point is sloooooowwwwww. 10s (or on some architectures even 100s) of cycles of latency, versus one cycle of latency for integer. Roguelikes have enough complicated stuff going on that this actually does matter. It's easy to end up with a compute-bound roguelike game simply by using floating point.

Today's processors are fast enough that you could get away with expressions like the above here and there, but back in the day it would have made the game unplayable. Maintainers have made the wise decision (whether or not they understood it (no implication intended)) to stick with an integer only design philosophy, thus avoiding painful FP creep.

If your integer division gives you unacceptable rounding errors, the solution is not to convert to float; it's to multiply all numerator terms by 10 (or 100, or whatever value gives you enough decimal places) and treat it as fixed point.
kandrc is offline   Reply With Quote