Floating point artithmetic and optimized .NET assemblies.

If you are familiar with floating point arithmetic you are aware that the number you set it to is most likely not stored as exactly what you set it to but a number very close to it. It will not be good for exact calculations like financial but might be suitable for others.
 
If you are familiar with the MS C++ compiler you might know about the /fp compiler option.This lets you control the compilers optimization when it comes to floating point arithmetic. They might differ and you are most likely aware of it as you can control it.
 
If you use C# compiler you basically have a single compiler option to optimize or not. In the remarks you will note:
/optimize also tells the common language runtime to optimize code at runtime.
 
What this does to the JIT is to use same optimizations as /fp:strict (or precise) when it is not an optimized build and /fp:fast when optimized.
 
For specified C# floating point arithmetic both not optimized and optimized compile generates the same immediate language assembler but the JIT will choose different paths dending on the optimize flag.
 
Apparantly this is by design in the .NET/JIT side and is just something you need to be aware of.

Leave a Reply

Your email address will not be published. Required fields are marked *