In what contexts do programming languages make real use of an Infinity value? In what contexts do programming languages make real use of an Infinity value? python python

In what contexts do programming languages make real use of an Infinity value?


Off the top of the head, it can be useful as an initial value when searching for a minimum value.

For example:

min = float('inf')for x in somelist:  if x<min:     min=x

Which I prefer to setting min initially to the first value of somelist

Of course, in Python, you should just use the min() built-in function in most cases.


Dijkstra's Algorithm typically assigns infinity as the initial edge weights in a graph. This doesn't have to be "infinity", just some arbitrarily constant but in java I typically use Double.Infinity. I assume ruby could be used similarly.


There seems to be an implied "Why does this functionality even exist?" in your question. And the reason is that Ruby and Python are just giving access to the full range of values that one can specify in floating point form as specified by IEEE.

This page seems to describe it well: http://steve.hollasch.net/cgindex/coding/ieeefloat.html

As a result, you can also have NaN (Not-a-number) values and -0.0, while you may not immediately have real-world uses for those either.