• 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
Strange behavior of -Wfloat-equal on clang (Xcode 5)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

Hi!

There's something strange with -Wfloat-equal warnings on clang from Xcode 5.

This warning is supposed to be triggered whenever two floating point values are compared for equality.

However, if I compile the following code with cc mytest.c -Wfloat-equal

[code begins here]
#include <stdio.h>
#include <stdlib.h>

intmain(int argc, char **argv)
{
float a=0.357;
float b=1.782;
if(a==b)
{
printf("This must trigger a warning from -Wfloat-equal.\n");
}
if(a==2.1)
{
printf("This must trigger a warning from -Wfloat-equal too.\n");
}
if(a==2.0)
{
printf("This must trigger a warning from -Wfloat-equal as well.\n");
}
return EXIT_SUCCESS;
}
[code ends here]

I'm getting warnings from just the first and second tests. The third test doesn't trigger a warning.

From more tests I did, it seems -Wfloat-equal doesn't trigger a warning if one operand is a floating point literal that can be casted to a integer exactly without data loss.

However, compiled it with llvm-gcc mytest.c -Wfloat-equal and all three tests generate a warning (which is the behavior I'm used too).

What's happening here?

If it helps, the clang version reported by my Xcode 5 installation is:

cc --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix

If anybody knows why is this happening, and how to get all these three warnings from clang, please tell!!

Btw, Happy New Year to all!

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: Fritz Anderson <email@hidden>
  • Prev by Date: Re: Strange problems using std::string and C++0x
  • Next by Date: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
  • Previous by thread: Re: Strange problems using std::string and C++0x
  • Next by thread: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
  • Index(es):
    • Date
    • Thread