www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Problem with cout

↑ ↓ ← 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
↑ ↓ → 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