Re: float confusion

From: Martin Ambuhl (mambuhl_at_earthlink.net)
Date: 01/18/04


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


Relevant Pages

  • [git patches] net driver updates for .26
    ... Fix a bug where the pointer never moves for dma_unmap... ... Update and fix driver debugging messages ... int reset); ... * header structure can be anywhere in the mcp. ...
    (Linux-Kernel)
  • [PATCH][PPC64] Handle altivec assist exception properly
    ... This is the PPC64 counterpart of the PPC32 Altivec assist exception ... Fortunately there are only a limited set of altivec instructions ... +static unsigned int eexp2 ... +/* Round to floating integer, ...
    (Linux-Kernel)
  • Re: Which delete statement is faster?
    ... So there is just one mapping pointer and extention ... ** 2) copy the file header attributes from the source directory, ... int sys$open, sys$connect, sys$read, sys$write, sys$close; ... ** We'll use this header to clone the target header into. ...
    (comp.os.vms)
  • Re: Parameter Name Warning?
    ... there is more to those names than just what the compiler does with them. ... You know only what you get in the header. ... correct for me in the watch window. ... >> int main ...
    (microsoft.public.vc.language)
  • Re: Inconsistent Program Results
    ... Replace this with which is the standard header you need ... main is an interface between you and the system. ... every time you get bored with int main, I suggest you stick to the ... at the end of a void function, ...
    (comp.lang.c)