Re: float confusion
From: Martin Ambuhl (mambuhl_at_earthlink.net)
Date: 01/18/04
- Next message: Martin Ambuhl: "Re: Float confusion"
- Previous message: Arthur J. O'Dwyer: "Re: Something wrong in my program"
- Next in thread: Nobody: "Re: float confusion"
- Reply: Nobody: "Re: float confusion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 18 Jan 2004 06:59:42 GMT
Nobody wrote:
> I'm trying to understand why this program...
>
> #include <stdio.h>
> #include <float.h>
You don't use this header for anything, so you needn't #include it.
>
> int
> main(void)
> {
> int i = 123456789 ;
> int j = 987654321 ;
>
> float k = i ;
> float m = j ;
> float n ;
> float p ;
>
> n = m / 1000000000 ;
>
> p = i + n ;
>
> printf( "%d %d %f %f %f %f %f\n", i, j, k, m, n, k + n, p ) ;
>
> return 0 ;
> }
>
> ...generates this output:
>
> 123456789 987654321 123456792.000000 987654336.000000 0.987654
> 123456792.987654 123456792.000000
There is plenty on floating point problems in the FAQ, so check there
first. Since floats need not have more than 6 significant digits, I fail
to see your problem.
-- Martin Ambuhl
- Next message: Martin Ambuhl: "Re: Float confusion"
- Previous message: Arthur J. O'Dwyer: "Re: Something wrong in my program"
- Next in thread: Nobody: "Re: float confusion"
- Reply: Nobody: "Re: float confusion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|