www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/11/08/07:01:39

Message-ID: <005501c2871e$2a5b9990$0100a8c0@p4>
From: "Andrew Cottrell" <acottrel AT ihug DOT com DOT au>
To: <djgpp-workers AT delorie DOT com>
Subject: Weird ceil() and other results
Date: Fri, 8 Nov 2002 22:57:47 +1100
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2800.1123
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1123
Reply-To: djgpp-workers AT delorie DOT com

If I comment out the #include <math.h> from the program below then the
program compiles and links without any errors or warnings. The results are:-
    date = 52.680000
    date = 51.680000
    decimalPart = 1072705824.000000
    wholePart = 1077938047.000000
    down = 1077939071.000000

If I include the #inclue <math.h> from the program below then the program
compiles and links without any errors or warnings. The results are:-
    date = 52.680000
    date = 51.680000
    decimalPart = 0.680000
    wholePart = 51.000000
    down = 52.000000

These results are correct....

Does anyone know why I would get wrong results, but no error messages if I
do not include math.h? I would have expected to get error messages
indicating a problem rather than a bad exe.

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#include <dir.h>
#include <string.h>
#include <time.h>
#include <limits.h>
int main()
{
    double date;
    double decimalPart = 0.0;
    double wholePart = 0.0;
    double down;

    date = 52.68;

    printf("date = %f\n", date);
    decimalPart = fmod( date, 1.0 );
    date -= 1.0;
    wholePart = (double) floor( date);
    down = ceil(date);

    printf("date = %f\n", date);
    printf("decimalPart = %f\n", decimalPart);
    printf("wholePart = %f\n", wholePart);
    printf("down = %f\n", down);

}



- Raw text -


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