How to represent -infinity in programming

前端 未结 6 1791
野趣味
野趣味 2021-01-17 01:18

How can I represent -infinity in C++, Java, etc.?

In my exercise, I need to initialize a variable with -infinity to show that it\'s a very

6条回答
  •  醉话见心
    2021-01-17 01:38

    You can have -Infinity as a floating point literal (at least in Java):

    double negInf = Double.NEGATIVE_INFINITY;
    

    It is implemented according to the IEEE754 floating point spec.

提交回复
热议问题