From d895265bcc649804b714938e51f20d72a8672383 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Tue, 26 Mar 2019 16:12:21 +0100 Subject: [PATCH] Make standalone consistent with runtime with regard to clocks Also cast integers to 64 bit instead of 32 bit --- brian2/devices/cpp_standalone/brianlib/clocks.h | 10 +++++----- brian2/devices/cpp_standalone/templates/network.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brian2/devices/cpp_standalone/brianlib/clocks.h b/brian2/devices/cpp_standalone/brianlib/clocks.h index b33168304..1617f98f9 100644 --- a/brian2/devices/cpp_standalone/brianlib/clocks.h +++ b/brian2/devices/cpp_standalone/brianlib/clocks.h @@ -19,7 +19,7 @@ class Clock double *dt; int64_t *timestep; double *t; - Clock(double _epsilon=1e-14) : epsilon(_epsilon) { i_end = 0;}; + Clock(double _epsilon=1e-8) : epsilon(_epsilon) { i_end = 0;}; inline void tick() { timestep[0] += 1; @@ -30,18 +30,18 @@ class Clock { int i_start = fround(start/dt[0]); double t_start = i_start*dt[0]; - if(t_start==start || fabs(t_start-start)<=epsilon*fabs(t_start)) + if(t_start==start || fabs(t_start-start)<=epsilon) { timestep[0] = i_start; } else { - timestep[0] = (int)ceil(start/dt[0]); + timestep[0] = (int64_t)ceil(start/dt[0]); } i_end = fround(end/dt[0]); double t_end = i_end*dt[0]; - if(!(t_end==end || fabs(t_end-end)<=epsilon*fabs(t_end))) + if(!(t_end==end || fabs(t_end-end)<=epsilon)) { - i_end = (int)ceil(end/dt[0]); + i_end = (int64_t)ceil(end/dt[0]); } } private: diff --git a/brian2/devices/cpp_standalone/templates/network.cpp b/brian2/devices/cpp_standalone/templates/network.cpp index 197d84696..6179c38dc 100644 --- a/brian2/devices/cpp_standalone/templates/network.cpp +++ b/brian2/devices/cpp_standalone/templates/network.cpp @@ -7,7 +7,7 @@ #include {{ openmp_pragma('include') }} -#define Clock_epsilon 1e-14 +#define Clock_epsilon 1e-8 double Network::_last_run_time = 0.0; double Network::_last_run_completed_fraction = 0.0;