I am having some problems with IEEE floating point rules that prevent compiler optimizations that seem obvious. For instance,
char foo(float x) { if (x == x) return 1; else return 0; }
cannot be optimized to just return 1, because NaN == NaN is false. Okay, fine, I think.
However, I want to write so that the optimizer can actually fix something for me. Are there mathematical identities for all floats? For example, I would like to write! (X - x), if that meant that the compiler could assume that it held on all the time (although this is also not the case).
I see some links to such identifiers on the Internet, for example here , but I did not find organized information, including an easy scan of the IEEE 754 standard.
It would be great if I could force the optimizer to accept isnormal (x) without generating additional code (in gcc or clang).
Obviously, I am not going to write (x == x) in my source code, but I have a function designed for inline. A function can be declared as foo (float x, float y), but often x is 0 or y is 0, or x and y are both z, etc. Floats are screen geometric coordinates. These are all cases when I manually encoded without using a function that I would never distinguish between 0 and (x - x), I would just optimize the dumb things. So, I really don't care about the IEEE rules in what the compiler does after turning on my function, and I would immediately ignore their compiler. Rounding differences are also not very important, since we mainly do a screen drawing.
I don’t think that -ffast-math is an option for me, because the function appears in the header file, and it doesn’t work that the .c files that use this function compile with -ffast-math.