rds95@leah.Albany.Edu (Robert Seals) (11/14/89)
Hello,
[I was considering posting this to comp.lang.c, but there has been a
generally poor response to system specific discussion there...especially
about pcs.]
Consider this program:
/*
* A program
*/
#include <stdio.h>
void main(void)
{
double g = 9.6;
printf("%lf %.0lf %.1lf\n", g, g, g);
}
/*
* end of a program
*/
I think that this should result in the line "9.600000 10 9.6\n" being printed
on standard output.
Turbo C in the small model prints "1" instead of "10"; it seems that whenever
the print format is "%.0lf" and the argument rounds to a power of 10,
printf and fprintf (haven't tried cprintf or sprintf) print 1 too few '0's.
This is bad news.
Workaround: Don't use "%.0lf"!!!
rob
tarvaine@tukki.jyu.fi (Tapani Tarvainen) (11/14/89)
In article <2158@leah.Albany.Edu> rds95@leah.Albany.Edu (Robert Seals) writes: > double g = 9.6; > > printf("%lf %.0lf %.1lf\n", g, g, g); >I think that this should result in the line "9.600000 10 9.6\n" being printed And that's exactly what it prints in my machine (regardless of memory model). Which version of TC do you have (I have 2.0)? -- Tapani Tarvainen (tarvaine@tukki.jyu.fi, tarvainen@finjyu.bitnet)
osh@cbnewsh.ATT.COM (david.a.oshinsky) (11/15/89)
In article <2158@leah.Albany.Edu> rds95@leah.Albany.Edu (Robert Seals) writes: > Turbo C in the small model prints "1" instead of "10"; it seems that whenever > the print format is "%.0lf" and the argument rounds to a power of 10, > printf and fprintf (haven't tried cprintf or sprintf) print 1 too few '0's. Patch files (named "patch.arc", "tc2pat.arc", and "td1pat.arc") have been circulating which fix a number of bugs in early "releases" of the Turbo C 2.0 package. Later "releases" were patched by Borland. Unfortunately, the "release" number (2.0) does not indicate which patches have been applied. The bugs are in stat(), printf(), td386.exe, tdh386.sys, and tlib.exe. The printf() bug is exactly the one which Robert Seals writes about. I'll send the patch files to those who send me e-mail. David Oshinsky AT&T Bell Laboratories Crawfords Corner Road, Room 2K334 Holmdel, NJ 07733 phone: (201)949-0037 uucp: att!quark!osh
TEITTINEN@cc.helsinki.fi (Marko) (11/15/89)
In article <2158@leah.Albany.Edu>, rds95@leah.Albany.Edu (Robert Seals) writes: [source code deleted...] > > I think that this should result in the line "9.600000 10 9.6\n" being printed > on standard output. > > Turbo C in the small model prints "1" instead of "10"; it seems that whenever > the print format is "%.0lf" and the argument rounds to a power of 10, > printf and fprintf (haven't tried cprintf or sprintf) print 1 too few '0's. > > Workaround: Don't use "%.0lf"!!! Another way to handle this is to find patches for TC. The patches can be found in SIMTEL20 in directory PD1:<MSDOS.TURBOC> (or was it <MSDOS.TC>?) -- E-Mail: teittinen@finuh.bitnet ! "Studying is the only way teittinen@cc.helsinki.fi ! to do nothing without Marko Teittinen, student of computer science ! anyone blaming you" -me
moorer@jacobs.CS.ORST.EDU (Rocky Moore) (11/15/89)
In article <2158@leah.Albany.Edu> you write: > >Turbo C in the small model prints "1" instead of "10"; it seems that whenever >the print format is "%.0lf" and the argument rounds to a power of 10, >printf and fprintf (haven't tried cprintf or sprintf) print 1 too few '0's. > >This is bad news. > >Workaround: Don't use "%.0lf"!!! > >rob The problem is certainly a bug. It only happens (in any model) when you have a number which when rounded off will increase the number of leading digits ( e.g. 999.9 9999.9 99.9 ect).. You should also note note to EVER forget to include math.h if you use something like the sine() or cos() functions. You will find that the printf() will seem to print just junk at times instead of the values supplied. It can cost you many hours of debugging when you have just forogt a header file. -Rocky Moore moorer@jacobs.cs.orst.edu - Let those who ride decide!