• Register
3,890 points
11 5 1
Welcome to Kodlogs, programming questions and answer website.

Infinity is defined is an undefined number that can be negative or positive. Any arithmetic operation that is performed on infinite value is always lead to an infinite number. These operations can be of addition, subtraction, multiplication, or any other.

In the field of computer science, infinity is used to measure the performance and optimize the algorithms that can perform computations on a wide scale of application.

Infinity in python:

In python, the concept of representing the infinity as an integer violates the definition of infinity itself. There is no way of representing the infinity as an integer in any programming language. But in python, float values can be used to represent an infinite integer due to its dynamic functionality. Once can use float(‘inf’) as an integer to represent the infinity.

Methods to represent infinity:

As the infinity can be positive or negative so they can be represented respectively as;

float(‘inf’)

float(‘-inf’)

Example Program:

This code will describe the implementation of all the discussed content.

# Defining a positive infinite integer

positive_infnity = float('inf')

print('Positive Infinity: ', positive_infnity)



# Defining a negative infinite integer

negative_infnity = float('-inf')

print('Negative Infinity: ', negative_infnity)

 

Output:

Positive Infinity: inf

Negative Infinity: -inf

 

3,890 points
11 5 1