6 ms·
For floating point math is this why I see "/2" written as "*0.5" all the time, and is that really necessary and can't compilers figure that out?
by lamontcg 6y ago
For floating point math is this why I see "/2" written as "*0.5" all the time, and is that really necessary and can't compilers figure that out?
- kevin_thibedeau 6y agoThey don't necessarily produce the same result and strict IEEE conformance prohibits such transformations. With GCC, --ffast-math enables optimizations like this.
- lamontcg 6y agoThat makes sense. I typically have to worry about larger relative tolerances anyway so I think I can start using that trick.
- SuchAnonMuchWow 6y agoIn this specific example, they do produce exactly the same result: `a / b` is completely equivalent to `a * (1 / b)` when both b and 1/b are perfectly representable in floating point without rounding, which is the case for 2 and 0.5