Skip to content
Related Articles

Related Articles

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

View Discussion
Improve Article
Save Article
  • Last Updated : 03 Oct, 2019
View Discussion
Improve Article
Save Article

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!