How do I set up my conditions in regular binary search so that I find the largest value x such that f(x) <= t for some critical value t? As opposed to accidentally returning the lowest number > t.

Right now my bounds are

```
if f(x) > t then high = x-1
else if f(x)< t then low = x+1
else return x
```

Main while loop is `while low <= high`

# Best How To :

How about this?

```
int ans = -1;
bsearch()
if f(x) > t then high = x-1
else if f(x)<= t then low = x+1, ans = x
```

Another method:

Just use your current bsearch to find the x where f(x) is smallest value > t, then what you want is just x - 1 ? (If exist)

PS: If you are using C++, you can use upper_bound() to find the position of x, then x-1 is your answer