Skip to content

Commit 79159a5

Browse files
author
Divya Kamath
committed
Fixed floating point error
1 parent 6f7dac6 commit 79159a5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Simulator/Core/Simulator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,14 @@ void Simulator::advanceEpoch(int currentEpoch) const
193193
while (g_simulationStep < endStep) {
194194
// Output status once every 1% of total simulation time
195195
if (count % onePercent == 0) {
196+
// Simulation time is calculated independently to handle deserialization scenarios.
197+
// If g_simulationStep is set to a value greater than totalDuration after deserialization,
198+
// a modulo operation is applied to ensure the displayed simulation time is accurate.
199+
// If totalDuration is zero, the entire simulation time is determined by g_simulationStep * deltaT_.
196200
uint64_t totalDuration = (epochDuration_ * numEpochs_) - 1;
197-
uint64_t simulatedTime = (uint64_t)(g_simulationStep * deltaT_) % totalDuration;
201+
auto simulatedTime
202+
= (totalDuration == 0 ? (g_simulationStep * deltaT_)
203+
: (uint64_t)(g_simulationStep * deltaT_) % totalDuration);
198204

199205
LOG4CPLUS_TRACE(consoleLogger_, "Epoch: " << currentEpoch << "/" << numEpochs_
200206
<< " simulating time: " << simulatedTime << "/"

0 commit comments

Comments
 (0)