Hi,
        With your program, if you print out some values of x and y, you
        can see that y become very very small after a couple of
        iterations.

        When y is too small, the following statement become true:

        z = x+y, z == x because y is too small and is ignored due to the
        fact that you declared z as double.

        therefor, (z=x+y, z>x) and (x+y>x) are different looping
        conditions.

        if you declare z as long double z then it should give you the
        same result.

Regards,

Shao.

Christophe TROESTLER [EMAIL PROTECTED] wrote:
> Hi the list,
> 
> I apologize if that is a little bit off topic but I am a bit puzzled
> and  I  know there  are  experts  on this  list.   I  would like  an
> explanation on why the two "for" below give different results.
> 
> Thanks,
> ChriS
> 
> 
> -.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-
> 
> 
> #include <stdio.h>
> 
> main()
> {
>   double x, y, z;
>   int t;
>   
>   for(x=.5, y=1./4., t=1;   z= x + y, z > x;   y /=2,  t++)
>     ;
>   printf("t=%i\n", t);
> 
>   for(x=.5, y=1./4., t=1;  x+y > x;   y /=2,  t++)
>     ;
>   printf("t=%i\n", t); 
> }
> 
> 
> -- 
> Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED] < /dev/null
> 
> 

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: [EMAIL PROTECTED]                                                  |___/ 
_____________________________________________________________________________

Reply via email to