NumericBox unsafe double conversion

Jan Holesovsky kendy at suse.cz
Mon Mar 18 05:51:01 PDT 2013


Hi Tamás,

Zolnai Tamás píše v Pá 15. 03. 2013 v 13:39 +0100:

>   I'm working with NumericBox nowadays and I recognised a problem
> belong to it. This class is a ComboBox which allows only numeric
> values. It use sal_Int64 for store its value but use double conversion
> internal for remformating. The problem is that this concept allows
> adding such sal_Int64 value which too large (contain too many digits?)
> so double conversion changes it in undefined way.
> For example: 92 233 720 368 547 750  change to 92 233 720 368 547 744
> on my system.

Can you please point exactly to the code in question, like
filename:line_number, or ClassName::MethodName, or something similar?
It helps a lot to understand what you have in mind, and saves the
guessing if it was (in this case) MetricField::ConvertValue() from
vcl/source/control/field.cxx, or something different :-)

In case you mean MetricField::ConvertValue( sal_Int64, ...) that calls
ConvertDoubleValue() as the first thing, I'd probably templatize it like

template <class type>
type implConvertValue( type nValue, sal_Int64 mnBaseValue, sal_uInt16
     nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit )
{
...
}

double MetricField::ConvertDoubleValue( ...params... )
{
    return implConvertValue< double >( ...params... );
}

sal_Int64 MetricField::ConvertValue( ...params... )
{
    return implConvertValue< sal_Int64 >( ...params... );
}

so that it is not necessary to cast to double and back, and always uses
the expected precision.

All the best,
Kendy




More information about the LibreOffice mailing list