This could be done with:
```
a = ((a + 180) % 360) - 180
```