avoid floating point multiplication and division to ensure reproducible results
This commit is contained in:
1 parent
8fcd5695d9
commit
618ba84f4f
21 files changed
+10
-6
No files matched your search
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.
+10
-6
@@ -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