Accurate event detection for simulating hybrid systems