//KM 2018 03 23: getting lots of form spam; screen out dates before 2000 (book publication date) Division isn't working as I expect. What's wrong? | Byte Craft Limited

Division isn't working as I expect. What's wrong?

In C, both multiply and divide return numbers of the same precision as their arguments. This implies:

x = a/b;

will lose the fractional part of the division.

x = a/b * 256;

will shift the result of the integer divide 8 bits to the left but will not regain the fractional bits from the division.

x = (a * 256) / b;

Will return an accum value (for instance: for 24 bit input values, a 16.8 result) for the division, but limits a to being 8 bits shorter without loss of precision.

x = ((a/b) * 256) + (((a % b) * 256) / b);

Will return an accum type (say 16.8) for the division, but restricts the result of the division to less than 16 bits for no precision loss.