I am given two numbers x and y in Python, and I'm asked if y represents a 10% decrease from x.
What is the best way of doing this without an if-statement? I am looking to vectorize this operation, so it'd be good to have a branchless form.
The verbose check would be:
def check(x,y):
if x < 0:
return y < x*1.1
else:
return y < x*0.9
I considered
def check(x,y):
return y < x * (1.1 if x < 0 else 0.9)
but that's just an inline if-statement.