• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)


  • Subject: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
  • From: Asiga Nael <email@hidden>
  • Date: Fri, 03 Jan 2014 19:54:18 +0000 (GMT)


El vie, 3 ene 2014 14:23 EST Sean McBride escribió:

>On Fri, 3 Jan 2014 18:28:29 +0000, Asiga Nael said:
>
>>First of all, I don't understand why a==2.1 triggers the warning and
>>a==2.0 doesn't.
>
>Then you need to read up on how floating point numbers are encoded... there is certainly much on the Internet about this.
>
>Not every decimal number can be expressed exactly as a floating point number.  You can see that here:
><http://www.h-schmidt.net/FloatConverter/>

According to such page, 2.1 has an exact representation in the IEEE format. Anyway, that's not the point. The point is that a fp comparison for equality isn't safe unless both operands aren't the result of fp math. If any of them is the result of a math operation, the comparison is unsafe even if one of the operands is a literal with an exact representation.

Give me a value that can be stored with an exact representation, let me store it on a floating point variable, and let me do a few operations which in theory should leave the value unmodified, and I'll manage to get a value slightly different from the original.

Any use I imagine of it is unsafe (end conditions for loops, branching depending on an fp math result, etc...)

asiga

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
      • From: Quincey Morris <email@hidden>
    • Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
      • From: Sean McBride <email@hidden>
  • Prev by Date: Re: Calling fopen() from a simple C++ program in Xcode 5.0.2 raises EXC_BAD_ACCESS, code=2
  • Next by Date: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
  • Previous by thread: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
  • Next by thread: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
  • Index(es):
    • Date
    • Thread