Em Sex, 2013-09-27 às 22:23 -0400, Martin Owens escreveu:
[...] So I guess I
need to make sure this isn't some C++ trick before I simplify it.

No C++ tricks here. Only IEEE floating points tricks. Maybe he wanted to avoid one of the *several* errors that can happen with floating points (where a + b + c could be different than c + b + a).

Without reasoning a lot, I can imagine the value could have a mantissa like "1.000000000x" and if he tries to divide by 10 (2 in binary), the x bit will go away thanks to the limit in the precision. Sure this problem could be solve by only manipulating the exponent, but maybe exponent is in the limit. If he subtracts -1.0 from the mantissa (but he is subtracting from the whole number, not manipulating the mantissa), it'll be possible to move the x bit to the left (changing the exponent) and a division by 10 wouldn't cause any data loss. BUT... this doesn't make sense, because his isn't subtracting -1^(some_numer_that_will_put_it_in_the_limit_of_exponent), then the operation "-1.0" won't help with this problem at all.

There are lots of possible errors with floating points and maybe I'm not seeing something here, but you tested the numbers and I wanted to give you confidence to simplify this code. If your test is correct, you are ready to go.

Maybe his intent was different and there was a special reason to do write this specific pattern, but I doubt (no comments around this code and something too specific to be probable).


--
Vinícius dos Santos Oliveira
https://about.me/vinipsmaker