From: Radical NetSurfer Newsgroups: comp.os.msdos.djgpp Subject: Re: modf BROKEN ?? Date: Tue, 01 Aug 2000 12:23:06 -0400 Message-ID: References: X-Newsreader: Forte Agent 1.8/32.548 X-No-Archive: yes MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 216.202.134.160 X-Original-NNTP-Posting-Host: 216.202.134.160 X-Trace: 1 Aug 2000 12:25:50 -0400, 216.202.134.160 Lines: 49 X-Original-NNTP-Posting-Host: 64.31.79.51 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com At 5.0, 6.0, etc, Fract display as "1.0" because of a rounding error in the printf output. Its only an "optical illusion", and if %3.21 is used, you won't see it. the question is obvious: HOW do I maintain a %3.3f output, but NOT get the 1.0 "optical illusion" ??? Thanks! On Mon, 31 Jul 2000 22:37:40 -0400, Radical NetSurfer wrote: >Why does the following program INCORRECTLY display >the fractional part? > >#include >#include >#include >#include > >#include >#include > >int main(int argc, char **argv) { >double i, f; >double v, y; > > printf("Observe the \"Rounded\" Value of Fint below:\n"); > printf("Use ESC to exit.\n\n"); > > for(v=0.0; v< 10; v+=0.1) { > f = modf(v, &i); // fractional = modf(argument, &integral); > if ( f <0.5 ) y = floor(v); > else y = ceil(v); > > printf("Value: %lf Fint: %lf Int: %lf Frac: %lf\n", > v, y, i, f ); > if ( getch() == 27 ) break; > } > >return (0); >} //main >------------------------------------------------------------------------------------------------------ >well? > >Email always welcomed: radsmail AT juno DOT com >http://members.tripod.com/~RadSurfer/