Is there a way to limit an integer value to a certain range without branching?
Posted
by Matt Wamboldt
on Stack Overflow
See other posts from Stack Overflow
or by Matt Wamboldt
Published on 2010-05-19T18:49:48Z
Indexed on
2010/05/19
19:00 UTC
Read the original article
Hit count: 195
Just out of curiosity. If I have something like:
if(x < 0)
x = 0;
if(x > some_maximum)
x = some_maximum;
return x;
Is there a way to not branch? This is c++.
© Stack Overflow or respective owner