summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2023-11-13 16:26:05 +0100
committerEike Rathke <erack@redhat.com>2023-11-13 19:37:49 +0100
commitd646341e5ddc625d9cf69777b4be174aebb43700 (patch)
tree8f4165da80f99865b14a14befd8a88eec4082a26
parent007e9e46d936ad7631792188168dffec7051b27f (diff)
Related: tdf#125580 Use tools::Duration constexpr accuracy epsilon values
Change-Id: I8f83c23206686ce23fb3f8be7d7098bbe252dc41 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159388 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
-rw-r--r--include/tools/duration.hxx8
-rw-r--r--sc/source/core/tool/interpr5.cxx4
2 files changed, 10 insertions, 2 deletions
diff --git a/include/tools/duration.hxx b/include/tools/duration.hxx
index 9fae80d1d7c9..9f032539e142 100644
--- a/include/tools/duration.hxx
+++ b/include/tools/duration.hxx
@@ -31,8 +31,13 @@ public:
minutes and seconds values here though. */
Duration(const Time& rStart, const Time& rEnd);
+ constexpr static sal_uInt64 kAccuracyEpsilonNanoseconds = 300;
+ constexpr static sal_uInt64 kAccuracyEpsilonNanosecondsMicroseconds = 999;
+
/** Difference in days, like DateTime()-DateTime().
+ Can also be used to round a date+time value to, for example, microseconds.
+
@param nAccuracyEpsilonNanoseconds
Round for example by 1 nanosecond if it's just 1 off to a
second, i.e. 0999999999 or 0000000001. This can be loosened if
@@ -41,7 +46,8 @@ public:
accuracy epsilon (=unsharpness) of ~300 is required. Hence default.
Must be 0 <= nAccuracyEpsilonNanoseconds <= Time::nanoSecPerSec - 1.
*/
- explicit Duration(double fTimeInDays, sal_uInt64 nAccuracyEpsilonNanoseconds = 300);
+ explicit Duration(double fTimeInDays,
+ sal_uInt64 nAccuracyEpsilonNanoseconds = kAccuracyEpsilonNanoseconds);
/** Time can be a limited duration as well and can have out-of-range
values, it will be normalized. Sign of both days and Time must be equal
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 90015018eec6..ae499ec492d1 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1344,7 +1344,9 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
{
// Limit to microseconds resolution on date inflicted or duration
// values of 24 hours or more.
- const sal_uInt64 nEpsilon = ((std::fabs(fVal1) >= 1.0 || std::fabs(fVal2) >= 1.0) ? 999 : 300);
+ const sal_uInt64 nEpsilon = ((std::fabs(fVal1) >= 1.0 || std::fabs(fVal2) >= 1.0) ?
+ ::tools::Duration::kAccuracyEpsilonNanosecondsMicroseconds :
+ ::tools::Duration::kAccuracyEpsilonNanoseconds);
if (_bSub)
PushDouble( ::tools::Duration( fVal1 - fVal2, nEpsilon).GetInDays());
else