delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/31/22:45:33

From: Radical NetSurfer <radsmail AT juno DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: modf BROKEN ??
Date: Mon, 31 Jul 2000 22:37:40 -0400
Message-ID: <crdcosk167oh81vpnjfqeg1bnls5qqg9ld@4ax.com>
X-Newsreader: Forte Agent 1.8/32.548
X-No-Archive: yes
MIME-Version: 1.0
NNTP-Posting-Host: 216.202.134.188
X-Original-NNTP-Posting-Host: 216.202.134.188
X-Trace: 31 Jul 2000 22:40:23 -0400, 216.202.134.188
Lines: 36
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

Why does the following program INCORRECTLY display
the fractional part?

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

#include <pc.h>
#include <unistd.h>

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019