Also,Please note that using relational/comparison operators with floating
point numbers/real numbers is not an advisable coding practice.

On Mon, May 30, 2011 at 8:12 PM, Dave <[email protected]> wrote:

> @vishal: Floats and doubles are stored in different formats, so
> looking at the first 8 hex digits of the two numbers isn't really
> helpful.
>
> The expression f < 0.8 is evaluated as (double)f < 0.8, so it would be
> more useful to print all 16 hex digits of (double)0.8f and 0.8. Then
> it would be easy to see that 0.08f < 0.08.
>
> Dave
>
> On May 29, 11:35 pm, Vishal Thanki <[email protected]> wrote:
> > you may want to check how the floats and doubles are stored into
> > memory using ieee notation.
> >
> > i tried to print 0.08 and 0.08f in hex format and got the following
> result.
> >
> > vishal@ubuntu:~/progs/c\ 10:03:56 AM >$ cat fl.c
> > #include <stdio.h>
> > int main()
> > {
> >         float f=0.08;
> >         if (f < 0.08f)
> >                 printf("hi\n");
> >         else
> >                 printf("hello\n");
> >
> >         printf ("%x %x\n",0.08, 0.08f);
> >         return 0;}
> >
> > vishal@ubuntu:~/progs/c\ 10:04:06 AM >$ gcc fl.c
> > fl.c: In function ‘main’:
> > fl.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but
> > argument 2 has type ‘double’
> > fl.c:10: warning: format ‘%x’ expects type ‘unsigned int’, but
> > argument 3 has type ‘double’
> > vishal@ubuntu:~/progs/c\ 10:04:11 AM >$ ./a.out
> > hello
> > 47ae147b 3fb47ae1
> > vishal@ubuntu:~/progs/c\ 10:04:14 AM >$
> >
> > ps: please ignore the warning in the code.
> >
> > On Sun, May 29, 2011 at 10:23 PM, sravanreddy001
> >
> >
> >
> > <[email protected]> wrote:
> > > and, I read it long time back that.. the value of 0.8 alone will be
> stored
> > > as 0.799999999995 (not sure on the number of 9's but.. the last digit
> in the
> > > precision will be a 5)
> > > that could be a reason.
> > > may be what "vishal" said is correct.
> >
> > > --
> > > 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.- 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].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Regards,
Ashish

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