Greg Young pinged me via IM to show me a problem he's run into - a bug in the C# compiler. Open up Visual Studio and start a C# console app. Paste the following code into the Main routine:
float low = 7f;
float high = 100f;
low = ((high + low) / 2f);
low = ((high + low) / 2f);
low = ((int)(low * 100f)) / 100f;
low = ((high + low) / 2f);
low = ((int)(low * 100f)) / 100f;
low = ((high + low) / 2f);
low = ((int)(low * 100f)) / 100f;
low = ((high + low) / 2f);
low = ((int)(low * 100f)) / 100f;
Console.WriteLine(low);
Console.ReadLine();
Press F5 to run with the debugger. Get a result. Press CTRL+F5 to run without the debugger. Get a different result.
Here is Greg's writeup of the problem.
Greg's already submitted this to Microsoft.
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
About Matt Ranlett
One of the two original Atlanta .NET Regular Guys, Matt fills his free time by helping to run several Atlanta area user groups, the Atlanta Code Camps, and works as one of the two INETA co-Vice Presidents of Technology