bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with GCC in Linux doing an addition


From: Frank Krauss
Subject: Problem with GCC in Linux doing an addition
Date: Mon, 16 Oct 2000 15:45:11 -0400

/*
Dear Sirs,

I have the following small program which seems to be giving me
results that do not appear to be correct.

I'm running this program on a COMPAQ Deskpro 66M P.C.
It has a Intel 486DX2 Processor.

It is running the Linux 2.0.35 Kernel from the Caldera Distribution.

The version of GCC that it is using is 2.7.2.3.

The commands to run this program that I'm using are:
   gcc program_name.c
   a.out

The purpose of this Program is to try to get just 2 positions to the
right of the Decimal, i.e. for Rounding Purposes.

Since I'm a New "C" Programmer, it may be that I'm doing something
wrong but I can not see what it is.

Any assistance that you can give me would be greatly appreciated.

Yours truly,

Frank Krauss

*/

main() 
{
float a = 3293.837646;
float b; 
int   c;
float d; 
float e; 
float f; 
float g; 
float h; 
printf(" Test Results\n");
printf(" \n");
printf(" a = %f\n",a);   /* original value */
b = a * 100;             /* multiply by 100 */  
printf(" b = %f\n",b);   
c = b;                   /* convert to integer */  
printf(" c = %d\n",c);  
d = c / 100;             /* divide by 100 */
printf(" d = %f\n",d);
e = c % 100;             /* get the remainder */
printf(" e = %f\n",e);  
f = e / 100;             /* divide the remainder by 100 */ 
printf(" f = %f\n",f); 
g = d + f;               /* add the integer and the result */
printf(" g = %f    Expected value was 3293        + .83     S/B = 
3293.83\n",g); 
h = g - .000078;
printf(" h = %f    Expected value was 3293.830078 - .000078 S/B = 
3293.83\n",h); 
printf(" \n");
printf(" End of Test Results\n");
}

/*

The results of running this program are the following output on the
Console.

 Test Results
 
 a = 3293.837646
 b = 329383.750000
 c = 329383
 d = 3293.000000
 e = 83.000000
 f = 0.830000
 g = 3293.830078    Expected value was 3293        + .83     S/B = 3293.83
 h = 3293.830078    Expected value was 3293.830078 - .000078 S/B = 3293.83
 
 End of Test Results
*/
    



reply via email to

[Prev in Thread] Current Thread [Next in Thread]