What do you think of:
```c++
p_bin += int(p_bin >= p_bins) * (p_bins - 1 - p_bin) 
```
This should avoid branching.