[Libreoffice-commits] core.git: tools/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sat Dec 19 15:06:01 UTC 2020
tools/source/generic/fract.cxx | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
New commits:
commit 67d83e40e2c4f3862c50e6abeabfc24a75119fc8
Author: Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Dec 19 13:25:53 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Dec 19 16:05:20 2020 +0100
speedup rational_FromDouble
multiplying/dividing by a power of 2 is much cheaper than
the equivalent operation on a factor of 10.
Change-Id: I31a7196a07649336378be867c67eb8a89fe6765f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108019
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx
index 8ec17b94a477..f5d2c88f4af8 100644
--- a/tools/source/generic/fract.cxx
+++ b/tools/source/generic/fract.cxx
@@ -400,8 +400,8 @@ SvStream& WriteFraction( SvStream& rOStream, const Fraction& rFract )
}
// If dVal > LONG_MAX or dVal < LONG_MIN, the rational throws a boost::bad_rational.
-// Otherwise, dVal and denominator are multiplied by 10, until one of them
-// is larger than (LONG_MAX / 10).
+// Otherwise, dVal and denominator are multiplied by 8, until one of them
+// is larger than (LONG_MAX / 8).
//
// NOTE: here we use 'sal_Int32' due that only values in sal_Int32 range are valid.
static boost::rational<sal_Int32> rational_FromDouble(double dVal)
@@ -411,11 +411,11 @@ static boost::rational<sal_Int32> rational_FromDouble(double dVal)
std::isnan(dVal) )
throw boost::bad_rational();
- const sal_Int32 nMAX = std::numeric_limits<sal_Int32>::max() / 10;
+ const sal_Int32 nMAX = std::numeric_limits<sal_Int32>::max() / 8;
sal_Int32 nDen = 1;
while ( std::abs( dVal ) < nMAX && nDen < nMAX ) {
- dVal *= 10;
- nDen *= 10;
+ dVal *= 8;
+ nDen *= 8;
}
return boost::rational<sal_Int32>( sal_Int32(dVal), nDen );
}
More information about the Libreoffice-commits
mailing list