While reading about floating point number precision I made a small test and expected the result1 to be true but it turned out to be the opposite. I somehow couldn't find a reasonable explanation, help please :)
Input
using System;
public class Program
{
public static void Main()
{
float a = 0.1f;
float b = 0.2f;
float c = 0.1f + 0.2f;
float d = a + b;
bool result1 = (a + b) == (0.1f + 0.2f);
bool result2 = c == d;
Console.WriteLine("result1 == " + result1);
Console.WriteLine("result2 == " + result2);
}
}
Output:
result1 == False
result2 == True