I have a weird problem in c# on visual studio 2013 (.NET framework 4.0):
When I compile an run the following code from the main thread:
//==========
double ddd = 300000.0;
ddd *= ddd;
Console.Write("The result is: " + ddd);
//==========
The result I get is: "The result is: 89999998976"
When I run the same code from a different thread in the same executable I get:
"The result is: 90000000000"
It looks like the double in the main thread is treated as float (32bits precision instead of 64bit precision).
Does anyone have any idea why it happens?
EDIT:
I found the answer. I'm using Managed DirectX. Apparently, you need to specify to directX device creation not to mess with the FPU precision (CreateFlags.FpuPreserve) otherwise doubles will be treated as floats.
For more info: floating point precision