3 ms·
It's typically faster to calculate a reciprocal (especially at compile time) and then multiply it, but this is often at the expense of precision. In C++, for e
by brrrrrm 5y ago
It's typically faster to calculate a reciprocal (especially at compile time) and then multiply it, but this is often at the expense of precision. In C++, for example, the -O3 flag on gcc will still emit a division (divss) to preserve compliant floating point precision in this example:
https://godbolt.org/z/PY3Wjno4P https://godbolt.org/z/PY3Wjno4P
However, when we enable `-ffast-math`, we permit the compiler to do a bit more aggressive optimization in this domain (trading off precision), and we see multiplication (mulss) is emitted:
https://godbolt.org/z/KEb1nc43z https://godbolt.org/z/KEb1nc43z