www.digitalmars.com         C & C++   DMDScript  

c++ - Problem with cout

reply Isle Choi <doncav shinbiro.com> writes:
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
parent Jan Knepper <jan smartsoft.cc> writes:
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