C++ Builder bug?

I ran into something strange with Borland’s C++ Builder. Try this

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.


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.

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.