Given const auto foo = 13.42
I would like to get the numbers fractional part, so .42
I'm leaning toward just using fmod
like: fmod(foo, 1.0)
But I could also just do foo / static_cast<int>(foo) - 1.0
Or perhaps some other mystical method.
Would there be a motivation for me to not simply use fmod
?
Two ways I can think of, either a cast or rounding down with
std::floor
Quick Bench Result shows the
fmod
approach as the slowest option by far, and the cast as the fastest: QuickBench