How to represent -infinity in programming

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

    You can't truly represent an infinite value because you've got to store it in a finite number of bits. There are symbolic versions of infinity in certain types (e.g. in the typical floating point specification), but it won't behave exactly like infinity in the strict sense. You'll need to include some additional logic in your program to emulate the behaviour you need.

提交回复
热议问题