Rather:

```c++
if (ts.tv_nsec < 0 || ts.tv_nsec >= 1e9)
{
  ts.tv_sec += ts.tv_nsec / 1e9;
  ts.tv_nsec = abs(ts.tv_nsec % 1e9);
}
```