Mail Archives: djgpp-workers/2003/08/13/10:07:35
On Tue, 12 Aug 2003 Kbwms AT aol DOT com wrote:
> In a message dated 8/12/2003 3:17:57 AM Eastern Standard Time,
> eliz AT elta DOT co DOT il writes:
>
> > Deduction, perhaps mistaken: after the first iteration thru this
> > loop:
> >
> > for (; integer &&p >= startp; ++expcnt)
> > {
> > tmp = modfl(integer * 0.1L , &integer);
> > *p-- = tochar((int)((tmp + .01L) * 10));
> > }
> >
> > the value of `integer' had a .375 as its fraction.
>
> A mistake is in multiplying by 0.1 instead of dividing by 10 and taking the
> remainder.
I agree. This should definitely divide by ten to produce as accurate
result as possible. Multiplying by 0.1 will cause errors when the
number has large absolute value. Could someone test the following patch
before I commit it?
Index: doprnt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doprnt.c,v
retrieving revision 1.16
diff -p -u -r1.16 doprnt.c
--- doprnt.c 30 Jun 2003 20:38:15 -0000 1.16
+++ doprnt.c 13 Aug 2003 07:58:17 -0000
@@ -587,7 +587,7 @@ cvtl(long double number, int prec, int f
*/
for (; integer && p >= startp; ++expcnt)
{
- tmp = modfl(integer * 0.1L , &integer);
+ tmp = modfl(integer / 10.0L , &integer);
*p-- = tochar((int)((tmp + .01L) * 10));
}
switch(fmtch)
--
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/
- Raw text -