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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/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");

chevron_right


Output:

inf
-inf

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/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");

chevron_right


Output:

Before function call: 78215936043546
After function call: inf

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/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");

chevron_right


Output:

Before function call: 78215936043546
After function call: -inf



My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :
    Practice Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.