Going back to the old school tricks that count on bool
converting to 1 if true
and 0 if false
:
static_cast <int>(foo + 0.5 - (foo < 0.0))
You should normally use library functions, but you can perform a performance test against this if this is a critical section
source
to share