by billcow » Apr 29, 2002 @ 6:55pm
The +0.5 is a rounding thing. Because of the way the ISO standard for floating point describes rounding, if you round to an int, it will always round down. If you add 0.5, anything that would round up using "real" rounding will end up with one added to the integer part, and the operation will occur correctly.
An interesting side note, this is the only function (round-to-int) that ISO says should round down. This causes problems on an x86 processor, because the compiler generates code that tells the FPU to change rounding modes, and as a result, it completely screws with the pipeline. The only way around this is to write an inline assembly function that rounds without setting the rounding mode.
I think the rounding issue occurs with int-to-float too.
Most people don't know that "A highly technical term" is actually a highly technical term used to describe something that doesn't mean anything