Agreed. I think trunc() is theoretically slightly faster than floor(), but either works fine. There's also std::modf, but unfortunately that's rather ugly to use.
Generally, you still need to check if your value is not infinite, but that's not needed here since we already have an upper bound.
View all comments
Show parent comment
14
u/Beowuwlf Aug 04 '21
It’s to check if the double is a whole number, right? If it’s not it will be greater than 0.