How to get a -0 result in floating point calculations and distinguish it from +0 in C#?

前端 未结 5 1654
难免孤独
难免孤独 2021-01-05 17:44

The MSDN documentation mentions that double type includes negative zero. However, both -1.0 / double.PositiveInfinity and -double.Epsilon / 2

5条回答
  •  鱼传尺愫
    2021-01-05 18:18

    After checking, I see that -1.0 / double.PositiveInfinity does return -0. Indeed, 1.0 / (-1.0 / double.PositiveInfinity) returns -infinity.

提交回复
热议问题