Floating point arithmetic is too reliable

前端 未结 9 1404
無奈伤痛
無奈伤痛 2021-01-16 09:45

I understand that floating point arithmetic as performed in modern computer systems is not always consistent with real arithmetic. I am trying to contrive a small C# progra

9条回答
  •  情深已故
    2021-01-16 10:11

    double x = (0.1 * 3) / 3;
    Console.WriteLine("x: {0}", x); // prints "x: 0.1"
    Console.WriteLine("x == 0.1: {0}", x == 0.1); // prints "x == 0.1: False"
    

    Remark: based on this don't make the assumption that floating point arithmetic is unreliable in .NET.

提交回复
热议问题