Answer by phuclv for Integer division, or float multiplication?
In your case, 5*j/4 would be much faster than 1.25*j because division by powers of 2 can be easily manipulated by a right shift, and 5*j can be done by a single instruction on many architectures such...
View ArticleAnswer by Eric Postpischil for Integer division, or float multiplication?
It is impossible to answer this question out of context. Additionally 5*j/4 does not generally produce the same result as (int) (1.25*j), due to properties of integer and floating-point arithmetic,...
View ArticleAnswer by Steve Jessop for Integer division, or float multiplication?
You've said all the values are dynamic, which makes a difference. For the specific values 5 * j / 4, the integer operations are going to be blindingly fast, because pretty much the worst case is that...
View ArticleInteger division, or float multiplication?
If one has to calculate a fraction of a given int value, say:int j = 78;int i = 5* j / 4;Is this faster than doing:int i = 1.25*j; // ?If it is, is there a conversion factor one could use to decide...
View Article