Kaydet (Commit) eb34ba3c authored tarafından Yuri Dario's avatar Yuri Dario

i150733: cast double to sal_Int64 can throw a EXCEPTION_FLT_INVALID_OPERATION on Windows.

üst 1abfdc98
...@@ -694,10 +694,14 @@ sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue ) const ...@@ -694,10 +694,14 @@ sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue ) const
sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue ) const sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue ) const
{ {
sal_Int64 nFactor = ImplPower10( GetDecimalDigits() ); sal_Int64 nFactor = ImplPower10( GetDecimalDigits() );
if((nValue < ( SAL_MIN_INT64 + nFactor )) ||
(nValue > ( SAL_MAX_INT64 - nFactor )))
return ( nValue / nFactor );
if( nValue < 0 ) if( nValue < 0 )
return ((nValue-(nFactor/2)) / nFactor ); return ((nValue-(nFactor/2)) / nFactor );
else else
return ((nValue+(nFactor/2)) / nFactor ); return ((nValue+(nFactor/2)) / nFactor );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -1247,13 +1251,18 @@ static double nonValueDoubleToValueDouble( double nValue ) ...@@ -1247,13 +1251,18 @@ static double nonValueDoubleToValueDouble( double nValue )
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits,
FieldUnit eInUnit, FieldUnit eOutUnit ) FieldUnit eInUnit, FieldUnit eOutUnit )
{ {
double nDouble = nonValueDoubleToValueDouble( ConvertDoubleValue(
(double)nValue, mnBaseValue, nDecDigits, eInUnit, eOutUnit ) );
sal_Int64 nLong ;
// caution: precision loss in double cast // caution: precision loss in double cast
return static_cast<sal_Int64>( if ( nDouble <= (double)SAL_MIN_INT64 )
// #150733# cast double to sal_Int64 can throw a nLong = SAL_MIN_INT64;
// EXCEPTION_FLT_INVALID_OPERATION on Windows else if ( nDouble >= (double)SAL_MAX_INT64 )
nonValueDoubleToValueDouble( nLong = SAL_MAX_INT64;
ConvertDoubleValue( (double)nValue, mnBaseValue, nDecDigits, else
eInUnit, eOutUnit ) ) ); nLong = static_cast<sal_Int64>( nDouble );
return ( nLong );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -1262,8 +1271,6 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_uInt16 nDigits, ...@@ -1262,8 +1271,6 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_uInt16 nDigits,
MapUnit eInUnit, FieldUnit eOutUnit ) MapUnit eInUnit, FieldUnit eOutUnit )
{ {
return static_cast<sal_Int64>( return static_cast<sal_Int64>(
// #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble( nonValueDoubleToValueDouble(
ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) ); ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) );
} }
......
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