4 ms·
Hmm? The A64 instruction set includes instructions to convert from floating point to integer and set the Inexact FPCR flag if the conversion isn't exact, which
by pm215 5y ago
Hmm? The A64 instruction set includes instructions to convert from floating point to integer and set the Inexact FPCR flag if the conversion isn't exact, which is pretty much exactly the operation we want here (it's one of the various FCVT insns). The catch is that Inexact is a sticky flag, so you'd need to clear it first. That might work out slower than "convert float to int, then int to float and see if you got back the same value" as the first C++ function does. It's also going to be awkward for a compiler to do so you'd be dropping down to inline asm. Would be interesting to benchmark, though.
(Edit: and as one of the blog post comments notes, for the special case of double to 32 bit integer the FCVTJS insn does this and puts the 'exact or not' information conveniently in the Z flag to branch on.)