October 19, 2001 Problem with cout | ||||
---|---|---|---|---|
| ||||
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 |
October 19, 2001 Re: Problem with cout | ||||
---|---|---|---|---|
| ||||
Posted in reply to Isle Choi | 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
|
Copyright © 1999-2021 by the D Language Foundation