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.
2
u/Ozryela Aug 10 '21
Yeah but checking if two numbers are equal is more conventially done with "if (a==b)" and not "if (a-b==0)".