[Libreoffice-commits] core.git: sal/rtl
BaiXiaochun (via logerrit)
logerrit at kemper.freedesktop.org
Tue Jun 29 21:19:21 UTC 2021
sal/rtl/math.cxx | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
New commits:
commit 9c15dea0b2192d231b65175291a7655122c2e24c
Author: BaiXiaochun <bai.xiaochun.mofan at protonmail.com>
AuthorDate: Sun Jun 27 18:38:10 2021 +0200
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Jun 29 23:18:47 2021 +0200
Simplify expresion
Reduce operation count by space / speed tradeoff.
This expression is widely used in LO.
Then needs to be fast.
Change-Id: Ic88cf15d451ec95a8ad6da88cd9f601cf2876871
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117954
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
Tested-by: Jenkins
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 7db362f35cfe..88354763b2b4 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -44,33 +44,20 @@
#include <dtoa.h>
-int const n10Count = 16;
-double const n10s[2][n10Count] = {
- { 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8,
- 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16 },
- { 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8,
- 1e-9, 1e-10, 1e-11, 1e-12, 1e-13, 1e-14, 1e-15, 1e-16 }
+constexpr int n10Count = 16;
+constexpr double n10s[n10Count*2+1] = {
+ 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9,
+ 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0,
+ 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8,
+ 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16 ,
};
// return pow(10.0,nExp) optimized for exponents in the interval [-16,16]
static double getN10Exp(int nExp)
{
- if (nExp < 0)
- {
- // && -nExp > 0 necessary for std::numeric_limits<int>::min()
- // because -nExp = nExp
- if (-nExp <= n10Count && -nExp > 0)
- return n10s[1][-nExp-1];
+ if (nExp < -n10Count || nExp > n10Count)
return pow(10.0, static_cast<double>(nExp));
- }
- if (nExp > 0)
- {
- if (nExp <= n10Count)
- return n10s[0][nExp-1];
-
- return pow(10.0, static_cast<double>(nExp));
- }
- return 1.0;
+ return n10s[nExp + n10Count];
}
namespace {
More information about the Libreoffice-commits
mailing list