Re: [xslt] number() floated?

On 2012-01-04 00:33:44 +0000, Laurence Rowe wrote:
> On 3 January 2012 22:33, Vincent Lefevre <vincent+gnome vinc17 org> wrote:
> > As a consequence, the output value should be "8.95" (like the input)
> > because 8.95 rounds to X and has less than 17 digits.
> You're right, xpath.c just prints DBL_DIG digits (a constant from
> float.h).

At least, this guarantees that when the value is read back in decimal,
this will give the same floating-point number.

BTW, I've just noticed that my examples with printf were incorrect:
I didn't pay attention to the fact that /usr/bin/printf uses the
long double type, and not the double type (this doesn't seem to be

> However, doing this properly is difficult, see:

The reference I have is

  author = {R.~G. Burger and R.~Kent Dybvig},
  title = {Printing Floating-Point Numbers Quickly and Accurately},
  booktitle =    {Proceedings of the {SIGPLAN'96} Conference on  Programming Languages Design and Implementation},
  year =         1996,
  pages =      {108--116},
  month =        jun,

but I see it is mentioned there. Then I agree that it may be
difficult, but not specifically for the XPath behavior. AFAIK,
printing with DBL_DIG digits seems easier just because it is
already implemented in the C library. :)

FYI, the wanted behavior is implemented in GNU MPFR, but that
would be overkill to use MPFR just for that (arbitrary precision
would be a nice extension, though).

Vincent Lefèvre <vincent vinc17 net> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]