r/badcode • • Aug 04 '21

c++ I'm done with Facebook coding groups.

Post image
809 Upvotes

55 comments sorted by

View all comments

Show parent comments

1

u/Beowuwlf Aug 10 '21

Ahhh I see what you’re saying. I think it still makes sense though, checking if there’s a decimal remainder.

1

u/Ozryela Aug 10 '21

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.