preventing negative remainder in ode and sde