Apple Clang Compiler Bug

I am in the process of moving an existing project to XCode 10.2 on Mojave, and I discovered a very disturbing behavior when converting a float to an int with the "-Ofast" compiler optimization option. In one of my C++ modules, I have the following statement:


int nVal1 = (int)sqrt((float)nNumImgsOnPage);


where nNumImgsOnPage is also declared as int.


When nNumImgsOnPage == 1, this operation incorrectly returns 0 when the project is compiled with -Ofast and 1 when compiled with other optimzation levels.


Is this a known bug in the Apple Clang compiler? Are there other such bugs?


Thank You



Larry

Replies

I would say it is a known byproduct of using -0fast. That option turns on a number of math caluclations that do not conform to standards.