#PSTip To infinity and beyond!

They say that PowerShell is the ultimate tool that provides almost infinite number of possible applications. So I wondered: What should I do to actually express infinity in PowerShell? The answer turned out to be fairly simple; the System.Double class implements static properties that represent both positive and negative infinity.

PS> [System.Double]::PositiveInfinity
Infinity

PS> [System.Double]::NegativeInfinity
-Infinity

The infinity number is defined as the result of division by zero, and we can, of course, confirm this definition:

PS> [Double]1/0
Infinity

You probably won’t use these ‘values’ often, but you should know they can be used similarly to any other number. You can for example test if the estimated number of all atoms in the observable Universe is less than infinite:

PS> 10e80 –lt [System.Double]::PositiveInfinity
True

About the author: Jakub Jareš

Jakub Jareš is an IT professional with strong background in Windows desktop systems. He started with Powershell a few months ago, and couldn't let go ever since. Showing that with the right attitude, a bit of effort and lot of practice you can become advanced in Powershell in no time.

Related Posts

%d bloggers like this: