NumericBox unsafe double conversion

Jan Holesovsky kendy at suse.cz
Wed Mar 20 08:15:23 PDT 2013


Hi Tamás,

Zolnai Tamás píše v Po 18. 03. 2013 v 17:56 +0100:


> And the problem was found in this function, in line 199:
> double nValue = rtl::OUString(aStr).toDouble();
> 
> 
> In general the NumericBox store its data in an sal_Int64 variable, but
> here this OUString->double conversion cause changes in big numbers.
> The "aStr" variable comes from GetText() function, which gives the
> NumericBox's content, so it is a string representation of an sal_Int64
> value. I don't know this behaviour is the expected from the
> OUString::toDouble() function, or it is a bug. 

Terribly sorry for my late answer.  I read the code there, and I'd just
kill the double from the code that is there (ie. from all the methods
that call ImplNumericGetValue() etc.), and instead of
OUString::toDouble() used OUString::toInt64().

The logic of ImplNumericGetValue() is that it splits the number to part
in front of the decimal point/comma, and after that, creates one
sal_Int64 number from that, and converts that to double.  Nevertheless,
later it is converted back to sal_Int64.  If the conversion to double
was there to avoid some overflows, the value will overflow anyway as
soon as you try to convert it back; but of course, you should be careful
when doing your changes, mostly in the area of conversions that include
multiplication.

Are you interested in this cleanup? :-)

All the best,
Kendy



More information about the LibreOffice mailing list