Kaydet (Commit) 46384365 authored tarafından Maarten Bosmans's avatar Maarten Bosmans Kaydeden (comit) Eike Rathke

Factor out common ScInterpreter::GetInt32() code

This might also be slightly more efficient because for
GetInt32WithDefault() when the value is missing, the
default value is not converted to and from double anymore.

Change-Id: I0a234265273086824f749b04aba022dd5cef322f
Reviewed-on: https://gerrit.libreoffice.org/29203Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst 680b1b59
......@@ -411,6 +411,7 @@ double GetDoubleFromMatrix(const ScMatrixRef& pMat);
double GetDouble();
double GetDoubleWithDefault(double nDefault);
bool IsMissing();
sal_Int32 double_to_int32(double fVal);
/** if GetDouble() not within int32 limits sets nGlobalError and returns SAL_MAX_INT32 */
sal_Int32 GetInt32();
/** if GetDoubleWithDefault() not within int32 limits sets nGlobalError and returns SAL_MAX_INT32 */
......
......@@ -2146,9 +2146,8 @@ double ScInterpreter::GetDoubleWithDefault(double nDefault)
return nResultVal;
}
sal_Int32 ScInterpreter::GetInt32()
sal_Int32 ScInterpreter::double_to_int32(double fVal)
{
double fVal = GetDouble();
if (!rtl::math::isFinite(fVal))
{
SetError( GetDoubleErrorValue( fVal));
......@@ -2175,33 +2174,18 @@ sal_Int32 ScInterpreter::GetInt32()
return static_cast<sal_Int32>(fVal);
}
sal_Int32 ScInterpreter::GetInt32()
{
return double_to_int32(GetDouble());
}
sal_Int32 ScInterpreter::GetInt32WithDefault( sal_Int32 nDefault )
{
double fVal = GetDoubleWithDefault( nDefault);
if (!rtl::math::isFinite(fVal))
{
SetError( GetDoubleErrorValue( fVal));
return SAL_MAX_INT32;
}
if (fVal > 0.0)
{
fVal = rtl::math::approxFloor( fVal);
if (fVal > SAL_MAX_INT32)
{
SetError( errIllegalArgument);
return SAL_MAX_INT32;
}
}
else if (fVal < 0.0)
{
fVal = rtl::math::approxCeil( fVal);
if (fVal < SAL_MIN_INT32)
{
SetError( errIllegalArgument);
return SAL_MAX_INT32;
}
}
return static_cast<sal_Int32>(fVal);
bool bMissing = IsMissing();
double fVal = GetDouble();
if ( bMissing )
return nDefault;
return double_to_int32(fVal);
}
sal_Int16 ScInterpreter::GetInt16()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment