Re: Funny Comparison with Float

Ryan Heath <[email protected]> Thu, 6 Mar 2008 15:15:44 +0100
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
Not to say that I am an floating expert :)

The literal 1.1 is a double.

You are comparing an float 1.1 with an double 1.1

Due to rounding errors, the double will contain a better approx. value
of 1.1 than the float does.

BTW, you never should check floats or doubles with an equal sign.
Always use a greater or less sign.

// Ryan

On Thu, Mar 6, 2008 at 2:57 PM, Brady Kelly <[email protected]> wrote:
> My colleague has just noticed a funny in comparing a float to a literal
> value.  Where 'version' is a 'float', the expression "version == 1.1"
> evaluates to false, where the comparison "version == 1.1F" does.  Last
> week's thread on floating point maths prompted me to raise the issue here to
> find out from the experts just what happens here.
>
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com