December 4th, 2009, 1:24 pm
QuoteOriginally posted by: AVtOk, INT_MAX = 2147483647 = 2^31 - 1 and FLT_MANT_DIG = 24 and beyond thatyou get your troubles (using VC++ 2005 here).#include<iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ double x; int n, k; n = INT_MAX; x = (float)(n); k = (int)x; cout << "n = " << n << ", x = " << x << ", k = " << k << endl << endl; n = 16777216 + 1; // 2^24 + 1 x = (float)(n); k = (int)x; cout << "n = " << n << ", x = " << x << ", k = " << k << endl << endl; n = 16777216 + 2; // 2^24 + 2 x = (float)(n); k = (int)x; cout << "n = " << n << ", x = " << x << ", k = " << k << endl << endl; n = 16777216 + 3; // 2^24 + 3 x = (float)(n); k = (int)x; cout << "n = " << n << ", x = " << x << ", k = " << k << endl << endl; system("PAUSE"); return 0;}givesn = 2147483647, x = 2.14748e+009, k = -2147483648n = 16777217, x = 1.67772e+007, k = 16777216n = 16777218, x = 1.67772e+007, k = 16777218n = 16777219, x = 1.67772e+007, k = 16777220For the rest you may wish to look up or search for rounding modes.Thanks AVT, the numbers I use are nowhere near that scale so it look like I am safe.Thank you to everyone who gave me help on this. I have learnt alot more about c++ variable storage through your responses. Chris