Karim BELABAS on Thu, 6 Feb 2003 17:56:16 +0100 (MET)

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

Re: realprecision bug

On Thu, 6 Feb 2003, Bill Allombert wrote:
> On Tue, Feb 04, 2003 at 11:06:53AM +0100, Karim BELABAS wrote:
> > P.S: confrac() has disappeared, convi() interface has changed, and will
> > change again soon. Currently, given a t_INT convi() returns the list of base
> > 10^9 digits, which is fast but inconvenient. I contemplate returning a
> > character string, which would make rounding 9 times slower, but would be much
> > easier to interface, for instance with the GMP kernel.
> I think the more important question is whether this will make IO faster
> by allowing to fputs() the whole number instead of writing each 9 digits
> block separatly, or not.

We already fputs() the whole number. Currently, when printing a floating
point number, we first convert it to a t_FRAC x/10^n, then

1.a) convi(x) returns a result in base 10^9
1.b) it is rounded properly, depending on the number of significant decimal
digits requested.
1.c) a string s is constructed from the set of blocks of 9 digits
2) a decimal point is inserted s --> s1.s2
3) puts(s1); putc('.'); puts(s2)

[ in fact 2) + 3) are implemented so that no copy is necessary. s1 is built
from inserting a NUL in s, then the corresponding digit is retored in order
to print s2 ]

What I am still considering is whether to switch to something like
1.a) convi(x) returns a string (integer printed in decimal)
1.b) it is rounded properly depending on the number of significant decimal
digits requested, decimal digit by decimal digit this time, instead of by
blocks of 9.
2) + 3) as before

I don't think it would make much difference in practice [ output is linear
time, conversion to base 10 is not ].

Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
PARI/GP Home Page: http://www.parigp-home.de/