PDA

View Full Version : C++ Builder bug?



ipo
03-18-2001, 11:29 AM
I ran into something strange with Borland's C++ Builder. Try this

[CODE]
void main(void) {
float x;
double y;

x = 2,585,463,658.2;
y = 2,585,463,658.2;
}

Trace the program and check the values of x and y. The value of y should be ok. However the value of x will be 2,585,463,552.

Or am I doing something wrong? I checked this on C++ Builder 3 and 4 but have not tried the other compilers.

ipo

Randolph
03-18-2001, 11:56 AM
double and float are types of number "with floating point", it means, that they are NOT exact types. So, if you write a=0.00000000000000000000000000000000001 any compiler will surely think, that you wrote a=0. The difference in your numbers was because of float has 32 bits, and double - 64. So, double can store more digits, than float, and also it can store larger number of zeros after or before the point.

ipo
03-18-2001, 01:58 PM
You're right. I had associated the C float type with the real Pascal type when in fact it should be equivalent to the single type.

thanks!