Commit 58430327 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Avoid division by zero in some rare cases when using the point-mass external potential

parent d04809b9
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "../config.h" #include "../config.h"
/* Some standard headers. */ /* Some standard headers. */
#include <float.h>
#include <math.h> #include <math.h>
/* Local includes. */ /* Local includes. */
...@@ -84,7 +85,10 @@ __attribute__((always_inline)) INLINE static float external_gravity_timestep( ...@@ -84,7 +85,10 @@ __attribute__((always_inline)) INLINE static float external_gravity_timestep(
const float a_2 = g->a_grav[0] * g->a_grav[0] + g->a_grav[1] * g->a_grav[1] + const float a_2 = g->a_grav[0] * g->a_grav[0] + g->a_grav[1] * g->a_grav[1] +
g->a_grav[2] * g->a_grav[2]; g->a_grav[2] * g->a_grav[2];
return potential->timestep_mult * sqrtf(a_2 / dota_2); if (fabsf(dota_2) > 0.f)
return potential->timestep_mult * sqrtf(a_2 / dota_2);
else
return FLT_MAX;
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment