C# - Inconsistent math operation result on 32-bit and 64-bit
- by david.healed
Consider the following code:
double v1 = double.MaxValue;
double r = Math.Sqrt(v1 * v1);
r = double.MaxValue on 32-bit machine
r = Infinity on 64-bit machine
We develop on 32-bit machine and thus unaware of the problem until notified by customer. Why such inconsistency happens? How to prevent this from happening?