Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#476 Float-to-string conversion problems

v8.7
closed
nobody
7
2012-10-08
2006-02-27
Michael Kay
No

In 8.7 a new module was introduced to handle
conversions from float/double to string. This module
can cause performance problems.

Because the algorithm uses floating-point arithmetic,
rounding errors can sometimes accumulate, and to
compensate for this, the algorithm applies a small
correction to the result as the last thing it does.
However, there are some cases where the number to be
formatted is close to a power of 10 (for example the
float 0.00001) where the rounding error causes the
intermediate result to be out by a factor of ten and in
this case the minal adjustment is applied millions of
times, causing chronically poor performance.

The algorithm used by this module,
FloatingPointConverter, was from a Java text book by
Jack Shirazi, but it has been found inadequate to meet
the requirements of the XPath conversion rules. I have
therefore implemented a new version of this module,
using an algorithm publish by Guy Steele and Jon White
in SIGPLAN '90: this algorithm uses integer arithmetic
only and gives much more reliable (and faster) results.
The new module is attached, and should be used as a
plug-in replacement for
net.sf.saxon.value.FloatingPointConverter.java

Michael Kay

Discussion

  • Michael Kay
    Michael Kay
    2006-02-27

    Replacement for net.sf.saxon.value.FloatingPointConverter