|
![](/i/fill.gif) |
Le 17/05/2013 12:31, Stephen a écrit :
> And why multiply by a half instead of dividing by two? Is that more
> computer/CPU friendly?
It might.
If the compiler/interpreter does not catch that the operation is easy to
perform with a single decrement of exponent (in case of IEEE-754 float)
or a single bit shift (in case of integer), the used assembly code is to
use the multiply opcode, instead of the divide opcode.
Division at opcode-level is far more cycles-hungry than a
multiplication. (especially with float format, but prediction on current
CPUs is dependent on too many variables to assert that without actual
benchmark)
Now, beware of premature optimisation.
It might also be just a style of programming (*0.5) to keep the equation
on a single text line. (whereas the /2 would need a 2 lines on
graphically accurate display)
Post a reply to this message
|
![](/i/fill.gif) |