avoid floating point multiplication and division to ensure reproducible results
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -120,14 +120,17 @@ TimeUnit<1>::TimeUnit (const std::string& s)
|
||||
iss.str (s);
|
||||
double v;
|
||||
iss >> v;
|
||||
m_data = HighPrecision (v * TimeStepPrecision::g_tsPrecFactor);
|
||||
m_data = HighPrecision (v);
|
||||
m_data.Mul (HighPrecision (TimeStepPrecision::g_tsPrecFactor, false));
|
||||
}
|
||||
|
||||
double
|
||||
TimeUnit<1>::GetSeconds (void) const
|
||||
{
|
||||
double timeValue = GetHighPrecision ().GetDouble ();
|
||||
return timeValue / TimeStepPrecision::g_tsPrecFactor;
|
||||
HighPrecision tmp = GetHighPrecision ();
|
||||
HighPrecision factor = HighPrecision (TimeStepPrecision::g_tsPrecFactor, false);
|
||||
tmp.Div (factor);
|
||||
return tmp.GetDouble ();
|
||||
}
|
||||
|
||||
int64_t
|
||||
@@ -285,9 +288,10 @@ std::istream& operator>> (std::istream& is, Time & time)
|
||||
|
||||
Time Seconds (double seconds)
|
||||
{
|
||||
double d_sec = seconds * TimeStepPrecision::g_tsPrecFactor;
|
||||
return Time (HighPrecision (d_sec));
|
||||
// return Time (HighPrecision ((int64_t)d_sec, false));
|
||||
HighPrecision tmp = HighPrecision (seconds);
|
||||
HighPrecision factor = HighPrecision (TimeStepPrecision::g_tsPrecFactor, false);
|
||||
tmp.Mul (factor);
|
||||
return Time (tmp);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
|
||||
Reference in New Issue
Block a user