@Priya: Most modern processors have arithmetic that conforms to the
IEEE Floating Point Standard. Double constants have 53 bits of
precision, while floats have 24 bits. Rounding depends on the bit to
the right of the 24th bit from the left. If that bit is a 1, the
number is rounded up, while 0 rounds down.

I should point out that with many language implementations, there is a
mechanism to control the rounding. While "round to nearest" is the
default, it also may be possible to "round up," "round down," or
"round to zero."

Dave

On Jan 8, 10:01 pm, priya mehta <priya.mehta...@gmail.com> wrote:
> 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.- Hide quoted text -
>
> - Show quoted text -

-- 
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