Is there a way to tell the compiler to compile with "fast-math" or something similar in C#?

207 views Asked by At

In some other languages, you can allow the compiler to perform some floating point optimizations, one of which is rewriting your code into algebraically equivalent expressions. Here are some examples of what I mean:

a = a * a * a * a * a * a * a * a * a * a * a * a * a * a * a * a;

could be optimized as

a *= a;
a *= a;
a *= a;
a *= a;

...

b /= 0.123456789f;
b /= 17;

could be optimized as

// b *= 1f / (0.123456789f * 17)
b *= 0.47647059257117651004476506493677f;

Obviously, compilers do not do this by default because the optimized expressions will produce different results, I thought there would be an attribute you can assign to a method or a class to say you are allowing these optimizations to take place, but I couldn't find anything.

0

There are 0 answers