How to represent -infinity in programming

前端 未结 6 1773
野趣味
野趣味 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:53

    You could define a number as -infinite and, when adding or substracting something from a number, you do first check if the variable was equal to that pseudo-number. If so you just leave it as it was.

    But you might find library functions giving you that functionality implemented, e.g Double in Java or std in c++.

提交回复
热议问题