c - Why does integer division truncation not occur here? -
i going through examples in k&r, , stumbled upon bit of code:
celcius=5 * (fahr-32) / 9;
the author says can't use 5/9 since integer division truncation lead value of 0.
the program however, outputs 17 answer when fahr=0. calculations, (0-32)/9 should lead -3 (due truncation) , -3*5 = -15, , not -17. why happen?
(0 - 32) first multiplied 5, giving -160. -160 / 9 = -17.
Comments
Post a Comment