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@collabora.com> Tested-by: Jenkins
This commit is contained in:
parent
a40334ef4d
commit
9c15dea0b2
1 changed files with 8 additions and 21 deletions
|
@ -44,33 +44,20 @@
|
||||||
|
|
||||||
#include <dtoa.h>
|
#include <dtoa.h>
|
||||||
|
|
||||||
int const n10Count = 16;
|
constexpr int n10Count = 16;
|
||||||
double const n10s[2][n10Count] = {
|
constexpr double n10s[n10Count*2+1] = {
|
||||||
{ 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8,
|
1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9,
|
||||||
1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16 },
|
1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0,
|
||||||
{ 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8,
|
1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8,
|
||||||
1e-9, 1e-10, 1e-11, 1e-12, 1e-13, 1e-14, 1e-15, 1e-16 }
|
1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16 ,
|
||||||
};
|
};
|
||||||
|
|
||||||
// return pow(10.0,nExp) optimized for exponents in the interval [-16,16]
|
// return pow(10.0,nExp) optimized for exponents in the interval [-16,16]
|
||||||
static double getN10Exp(int nExp)
|
static double getN10Exp(int nExp)
|
||||||
{
|
{
|
||||||
if (nExp < 0)
|
if (nExp < -n10Count || nExp > n10Count)
|
||||||
{
|
|
||||||
// && -nExp > 0 necessary for std::numeric_limits<int>::min()
|
|
||||||
// because -nExp = nExp
|
|
||||||
if (-nExp <= n10Count && -nExp > 0)
|
|
||||||
return n10s[1][-nExp-1];
|
|
||||||
return pow(10.0, static_cast<double>(nExp));
|
return pow(10.0, static_cast<double>(nExp));
|
||||||
}
|
return n10s[nExp + n10Count];
|
||||||
if (nExp > 0)
|
|
||||||
{
|
|
||||||
if (nExp <= n10Count)
|
|
||||||
return n10s[0][nExp-1];
|
|
||||||
|
|
||||||
return pow(10.0, static_cast<double>(nExp));
|
|
||||||
}
|
|
||||||
return 1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
Loading…
Reference in a new issue