I have release and debug codes that can give dramatically different results. Since I can't debug release code I have been printing value to a file to compare the two modes. I have localized my problem to a few lines of code.
var yFloat = topArcDetails.ArcPoints.GetInterpolatedYAt(point.X);
var tvdOnTopHorizon = (double) yFloat;
var yPointDouble = (double) point.Y;
deltaTvdTop = yPointDouble - tvdOnTopHorizon;
if (point.X == 2102.0 && point.Y > 1573.0 && point.Y < 1574.0)
{
var message = String.Format("MD, TVD, tvdOnTopHorizon, deltaTvdTop = {0} {1} {2} {3}", point.X, point.Y, tvdOnTopHorizon, deltaTvdTop);
//var message = String.Format("MD, TVD, yFloat, tvdOnTopHorizon, deltaTvdTop = {0} {1} {2} {3} {4}", point.X, point.Y, yFloat, tvdOnTopHorizon, deltaTvdTop);
var oldOut = Console.Out;
using (TextWriter w = File.AppendText("debugOutput.txt"))
{
Console.SetOut(w);
Console.WriteLine(message);
}
Console.SetOut(oldOut);
}
Note that I have two choices of the message I can print to file. One message contains the value of yFloat, the other does not.
If I run in release mode without debugging the first message will give:
MD, TVD, tvdOnTopHorizon, deltaTvdTop = 2102 1573.135 1554.6184437573 18.5164439380169
The second message will give:
MD, TVD, yFloat, tvdOnTopHorizon, deltaTvdTop = 2102 1573.135 1554.618 1554.61840820313 18.5164794921875
Notice that just printing the value of yFloat causes small changes in the last two numbers. In debug mode I see no difference caused by the print statement the two results are:
MD, TVD, yFloat, tvdOnTopHorizon, deltaTvdTop = 2102 1573.135 1554.618 1554.61840820313 18.5164794921875
MD, TVD, tvdOnTopHorizon, deltaTvdTop = 2102 1573.135 1554.61840820313 18.5164794921875
The debug result agree with the release results where yFloat is printed. I know that the core issue is the fact that the code mixes floating point and doubles, which was someone else's bad idea. Although printing the value of yFloat fixes the problem, I don't think that is very practical. It does make me think that there must be something I can do to get the release version to agree with the debug version.