Floating point arithmetic is too reliable

前端 未结 9 1315
無奈伤痛
無奈伤痛 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:07

    My favourite demonstration boils down to

    double d = 0.1;
    d += 0.2;
    d -= 0.3;
    
    Console.WriteLine(d);
    

    The output is not 0.

提交回复
热议问题