why is 1 double rounded down and the other double rounded up
is it compiler dependent?



On Sun, Jan 9, 2011 at 9:29 AM, Dave <dave_and_da...@juno.com> wrote:

> The 275.7 and 75.7 are doubles. The assignment statements round the
> double constant to float precision. Then you compare the unrounded
> double to the rounded float. If you had used 275.7e0 and 75.7e0 in the
> if statements, the results would have been "Hello" in both cases.
>
> Or to put it differently, 275.7 != 275.7e0 (not surprising) and 75.7 !
> = 75.7e0 (ditto), but one double is greater than the float because the
> double is rounded down to form the float and the other is less than
> the float because the double is rounded up to form the float.
>
> Dave
>
> On Jan 8, 8:24 pm, priya mehta <priya.mehta...@gmail.com> wrote:
>  > #include<stdio.h>
> > int main()
> > {
> > float a=275.7;
> > if(275.7>a)
> >     printf("Hi");
> > else
> >     printf("Hello");
> > return 0;
> >
> > }
> >
> > #include<stdio.h>
> > int main()
> > {
> > float a=75.7;
> > if(75.7>a)
> >     printf("Hi");
> > else
> >     printf("Hello");
> > return 0;
> >
> > }
> >
> > why the above two programs give different output?
>
> --
>  You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to