For example, in prim/fun/square.hpp. Note that some care must be taken to avoid changing the rounding behavior by casting the input before multiplying
With default toolchain settings (gcc/clang default to -fmath-errno), std::pow must set errno on domain/range/overflow errors, so the optimizer cannot rewrite it to a multiply in general.
glibc's pow is a branchy multi-path implementation where x * x is one instruction.
Originally posted by @sims1253 in #3368
For example, in
prim/fun/square.hpp. Note that some care must be taken to avoid changing the rounding behavior by casting the input before multiplyingOriginally posted by @sims1253 in #3368