to add to @Dave's reply. He explained it elaborately in
this<http://groups.google.com/group/algogeeks/browse_thread/thread/20af6e098297d413>thread


Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks
of Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.


On Sun, Jan 9, 2011 at 9:56 AM, Dave <[email protected]> wrote:

> @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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<algogeeks%[email protected]>
> <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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to