summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-01-06 10:10:39 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-01-06 11:38:01 +0100
commit2298b055cab8cf8d0268ee1375a5c6e416bf1332 (patch)
tree1fe4b266d730e13591506434ccbbeefe9cd053ff /tools/source
parent9b36cae4ca95ab9508752f2a13a45d09c3dbd87f (diff)
move the bigint based Scale() implementations to one central place
Picking the best looking one in the process. Change-Id: I77f9236fcd21f883a23fe2f43f20336f17b44cc6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108831 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools/source')
-rw-r--r--tools/source/generic/bigint.cxx16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/source/generic/bigint.cxx b/tools/source/generic/bigint.cxx
index 62350a30c311..6616ef76f423 100644
--- a/tools/source/generic/bigint.cxx
+++ b/tools/source/generic/bigint.cxx
@@ -843,4 +843,20 @@ bool operator<( const BigInt& rVal1, const BigInt& rVal2 )
return nA.bIsNeg ? (nA.nNum[i] > nB.nNum[i]) : (nA.nNum[i] < nB.nNum[i]);
}
+tools::Long BigInt::Scale( tools::Long nVal, tools::Long nMul, tools::Long nDiv )
+{
+ BigInt aVal( nVal );
+
+ aVal *= nMul;
+
+ if ( aVal.IsNeg() != ( nDiv < 0 ) )
+ aVal -= nDiv / 2; // for correct rounding
+ else
+ aVal += nDiv / 2; // for correct rounding
+
+ aVal /= nDiv;
+
+ return tools::Long( aVal );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */