c++ - Problem with cout
- Isle Choi (24/24) Oct 19 2001 I'm having trouble with IOSTREAM.
- Jan Knepper (5/29) Oct 19 2001 Try using 'double' instead of 'float'!
I'm having trouble with IOSTREAM. What is the problem ? (I'm using DMC++ 8.20.) ---------------------------------- #include <stream.h> void main() { float a,b; a=1; b=0.05; cout << a << " - " << b << " = " << a-b << endl; b=0.005; cout << a << " - " << b << " = " << a-b << endl; b=0.0005; cout << a << " - " << b << " = " << a-b << endl; } ----------------------------------- C:\Temp>sc float.cpp link float,,,user32+kernel32/noi; C:\Temp>float 1 - 0.05 = 0.95 1 - 0.00499999 = 0.995 ~~~~~~~ 1 - 0.0005 = 0.9995
Oct 19 2001
Try using 'double' instead of 'float'! You are using a 4 byte floating point and expect great precision!? Jan Isle Choi wrote:I'm having trouble with IOSTREAM. What is the problem ? (I'm using DMC++ 8.20.) ---------------------------------- #include <stream.h> void main() { float a,b; a=1; b=0.05; cout << a << " - " << b << " = " << a-b << endl; b=0.005; cout << a << " - " << b << " = " << a-b << endl; b=0.0005; cout << a << " - " << b << " = " << a-b << endl; } ----------------------------------- C:\Temp>sc float.cpp link float,,,user32+kernel32/noi; C:\Temp>float 1 - 0.05 = 0.95 1 - 0.00499999 = 0.995 ~~~~~~~ 1 - 0.0005 = 0.9995
Oct 19 2001