Open In App

Perl | Math::BigInt->binf() method

Improve
Improve
Like Article
Like
Save
Share
Report

Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.

binf() method of Math::BigInt module is used to create a new object with value infinity and if used on an existing object, it sets it to infinity.

Syntax: Math::BigInt->binf()

Parameter:
plus or minus: to set the sign of infinity as ‘+’ or ‘-‘

Returns: object with value inf

Example 1:




#!/usr/bin/perl  
    
# Import Math::BigInt module 
use Math::BigInt; 
   
# Create a BigInt object 
$x = Math::BigInt->binf();
  
# Object created with binf()
print("$x\n");
  
# Create a BigInt object 
$x = Math::BigInt->binf('-');
  
# Object created with binf()
print("$x");


Output:

inf
-inf

Example 2:




#!/usr/bin/perl  
    
# Import Math::BigInt module 
use Math::BigInt; 
    
# Specify number 
$num = 78215936043546; 
    
# Create BigInt object 
$x = Math::BigInt->new($num); 
  
# Object before function call
print("Before function call: $x\n"); 
  
# Calling the function
$x->binf();
  
# Object after function call
print("After function call: $x");


Output:

Before function call: 78215936043546
After function call: inf

Example 3:




#!/usr/bin/perl  
    
# Import Math::BigInt module 
use Math::BigInt; 
    
# Specify number 
$num = 78215936043546; 
    
# Create BigInt object 
$x = Math::BigInt->new($num); 
  
# Object before function call
print("Before function call: $x\n"); 
  
# Calling the function with '-' sign
$x->binf('-');
  
# Object after function call
print("After function call: $x");


Output:

Before function call: 78215936043546
After function call: -inf


Last Updated : 03 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads