include/svl/zformat.hxx | 8 ++++---- svl/source/numbers/zformat.cxx | 27 ++++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-)
New commits: commit 44d17f8feca372acd41142d1b607d3360282bf30 Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue Oct 13 21:41:45 2020 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jan 6 11:47:06 2021 +0100 Resolves: tdf#137453 Implicit conversion from sal_uInt64 to sal_Int32 is bad.. Change-Id: I5681249808cf623d3b7df09988f285268ea8d85f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104255 Tested-by: Jenkins Reviewed-by: Eike Rathke <er...@redhat.com> (cherry picked from commit 18f8a7056ac7b4677f4d99aac24ed2db44010140) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108730 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx index 089a4b0e48e6..3dbc0f925ceb 100644 --- a/include/svl/zformat.hxx +++ b/include/svl/zformat.hxx @@ -657,8 +657,8 @@ private: SVL_DLLPRIVATE void ImpGetFractionElements( double& fNumber, sal_uInt16 nIx, double& fIntPart, - sal_uInt64& nFrac, - sal_uInt64& nDiv ) const; + sal_Int64& nFrac, + sal_Int64& nDiv ) const; SVL_DLLPRIVATE bool ImpGetFractionOutput(double fNumber, sal_uInt16 nIx, OUStringBuffer& OutString); @@ -697,10 +697,10 @@ private: // normal digits or other digits, depending on ImpSvNumFor.aNatNum, // [NatNum1], [NatNum2], ... - SVL_DLLPRIVATE OUString ImpGetNatNumString( const SvNumberNatNum& rNum, sal_Int32 nVal, + SVL_DLLPRIVATE OUString ImpGetNatNumString( const SvNumberNatNum& rNum, sal_Int64 nVal, sal_uInt16 nMinDigits ) const; - OUString ImpIntToString( sal_uInt16 nIx, sal_Int32 nVal, sal_uInt16 nMinDigits = 0 ) const + OUString ImpIntToString( sal_uInt16 nIx, sal_Int64 nVal, sal_uInt16 nMinDigits = 0 ) const { const SvNumberNatNum& rNum = NumFor[nIx].GetNatNum(); if ( nMinDigits || rNum.IsComplete() ) diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 9bffb0d833e2..203f27e3ad51 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -63,6 +63,7 @@ const double EXP_ABS_UPPER_BOUND = 1.0E15; // use exponential notation above th } // namespace const double D_MAX_U_INT32 = double(0xffffffff); // 4294967295.0 +constexpr double D_MAX_INTEGER = (sal_uInt64(1) << 53) - 1; const double D_MAX_D_BY_100 = 1.7E306; const double D_MIN_M_BY_1000 = 2.3E-305; @@ -2759,7 +2760,7 @@ double SvNumberformat::GetRoundFractionValue ( double fNumber ) const { sal_uInt16 nIx = GetSubformatIndex ( fNumber ); double fIntPart = 0.0; // integer part of fraction - sal_uInt64 nFrac = 0, nDiv = 1; // numerator and denominator + sal_Int64 nFrac = 0, nDiv = 1; // numerator and denominator double fSign = (fNumber < 0.0) ? -1.0 : 1.0; // fNumber is modified in ImpGetFractionElements to absolute fractional part ImpGetFractionElements ( fNumber, nIx, fIntPart, nFrac, nDiv ); @@ -2770,7 +2771,7 @@ double SvNumberformat::GetRoundFractionValue ( double fNumber ) const } void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, - double& fIntPart, sal_uInt64& nFrac, sal_uInt64& nDiv ) const + double& fIntPart, sal_Int64& nFrac, sal_Int64& nDiv ) const { if ( fNumber < 0.0 ) fNumber = -fNumber; @@ -2780,7 +2781,7 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, nDiv = lcl_GetDenominatorString( rInfo, NumFor[nIx].GetCount() ).toInt32(); if( nDiv > 0 ) { // Forced Denominator - nFrac = static_cast<sal_uInt64>(floor ( fNumber * nDiv )); + nFrac = static_cast<sal_Int64>(floor ( fNumber * nDiv )); double fFracNew = static_cast<double>(nFrac) / static_cast<double>(nDiv); double fFracNew1 = static_cast<double>(nFrac + 1) / static_cast<double>(nDiv); double fDiff = fNumber - fFracNew; @@ -2792,8 +2793,8 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, else // Calculated Denominator { nDiv = 1; - sal_uInt64 nBasis = static_cast<sal_uInt64>(floor( pow(10.0,rInfo.nCntExp))) - 1; // 9, 99, 999 ,... - sal_uInt64 nFracPrev = 1, nDivPrev = 0, nFracNext, nDivNext, nPartialDenom; + sal_Int64 nBasis = static_cast<sal_Int64>(floor( pow(10.0,rInfo.nCntExp))) - 1; // 9, 99, 999 ,... + sal_Int64 nFracPrev = 1, nDivPrev = 0, nFracNext, nDivNext, nPartialDenom; double fRemainder = fNumber; // Use continued fraction representation of fNumber @@ -2801,7 +2802,7 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, while ( fRemainder > 0.0 ) { double fTemp = 1.0 / fRemainder; // 64bits precision required when fRemainder is very weak - nPartialDenom = static_cast<sal_uInt64>(floor(fTemp)); // due to floating point notation with double precision + nPartialDenom = static_cast<sal_Int64>(floor(fTemp)); // due to floating point notation with double precision fRemainder = fTemp - static_cast<double>(nPartialDenom); nDivNext = nPartialDenom * nDiv + nDivPrev; if ( nDivNext <= nBasis ) // continue loop @@ -2814,11 +2815,11 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, } else // calculate collateral fraction and exit { - sal_uInt64 nCollat = (nBasis - nDivPrev) / nDiv; + sal_Int64 nCollat = (nBasis - nDivPrev) / nDiv; if ( 2 * nCollat >= nPartialDenom ) { - sal_uInt64 nFracTest = nCollat * nFrac + nFracPrev; - sal_uInt64 nDivTest = nCollat * nDiv + nDivPrev; + sal_Int64 nFracTest = nCollat * nFrac + nFracPrev; + sal_Int64 nDivTest = nCollat * nDiv + nDivPrev; double fSign = (static_cast<double>(nFrac) > fNumber * static_cast<double>(nDiv))?1.0:-1.0; if ( fSign * ( double(nFrac * nDivTest + nDiv * nFracTest) - 2.0 * double(nDiv * nDivTest) * fNumber ) > 0.0 ) { @@ -2850,7 +2851,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, const OUString sNumeratorFormat = lcl_GetNumeratorString(rInfo, nCnt); const OUString sDenominatorFormat = lcl_GetDenominatorString(rInfo, nCnt); - sal_uInt64 nFrac = 0, nDiv = 1; + sal_Int64 nFrac = 0, nDiv = 1; double fNum = floor(fNumber); // Integral part if (fNum > D_MAX_U_INT32 || rInfo.nCntExp > 9) // Too large @@ -2871,12 +2872,12 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, { double fNum1 = fNum * static_cast<double>(nDiv) + static_cast<double>(nFrac); - if (fNum1 > D_MAX_U_INT32) + if (fNum1 > D_MAX_INTEGER) { sBuff = ImpSvNumberformatScan::GetErrorString(); return false; } - nFrac = static_cast<sal_uInt64>(floor(fNum1)); + nFrac = static_cast<sal_Int64>(floor(fNum1)); } else if (fNum == 0.0 && nFrac != 0) { @@ -5478,7 +5479,7 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords, } OUString SvNumberformat::ImpGetNatNumString( const SvNumberNatNum& rNum, - sal_Int32 nVal, sal_uInt16 nMinDigits ) const + sal_Int64 nVal, sal_uInt16 nMinDigits ) const { OUString aStr; if ( nMinDigits ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits