Mail Archives: djgpp-workers/2003/08/18/11:08:51
On Fri, 15 Aug 2003, Esa A E Peuha wrote:
> I do. :-) This is really a classic case of the wrong way to compute
> remainder modulo something; this patch does it the right way:
Actually, it doesn't; if the number is greater than 2^64, this could
put random garbage on the string. So we need to test the return value
of modfl to see if we can know the digit at all. This should really do
it right:
Index: doprnt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doprnt.c,v
retrieving revision 1.16
diff -c -p -r1.16 doprnt.c
*** doprnt.c 30 Jun 2003 20:38:15 -0000 1.16
--- doprnt.c 18 Aug 2003 08:10:15 -0000
*************** cvtl(long double number, int prec, int f
*** 579,594 ****
else doextradps=1;
}
/*
! * get integer portion of number; put into the end of the buffer; the
! * .01 is added for modf(356.0 / 10, &integer) returning .59999999...
* The test p >= startp is due to paranoia: buffer length is guaranteed
* to be large enough, but if tmp is somehow a NaN, this loop could
* eventually blow away the stack.
*/
for (; integer && p >= startp; ++expcnt)
{
! tmp = modfl(integer * 0.1L , &integer);
! *p-- = tochar((int)((tmp + .01L) * 10));
}
switch(fmtch)
{
--- 579,596 ----
else doextradps=1;
}
/*
! * get integer portion of number; put into the end of the buffer.
* The test p >= startp is due to paranoia: buffer length is guaranteed
* to be large enough, but if tmp is somehow a NaN, this loop could
* eventually blow away the stack.
*/
for (; integer && p >= startp; ++expcnt)
{
! if(modfl(integer / 10.0L , &tmp))
! *p-- = tochar((int)(integer - (tmp * 10.0L)));
! else
! *p-- = '0';
! integer = tmp;
}
switch(fmtch)
{
--
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/
- Raw text -