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

Last Updated : 3 Oct, 2019
Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators. bneg() method of Math::BigInt module is used to change the value of input to its negative value and does nothing for zero or NAN values
Syntax: Math::BigInt->bneg() Parameter: No Parameter Returns: object with value negated value
Example 1: perl
#!/usr/bin/perl  
  
# Import Math::BigInt module 
use Math::BigInt; 
  
# Specify number 
$num = 78215936043546; 

# Create BigInt object 
$x = Math::BigInt->new($num); 

$x->bneg();

print($x);
Output:
-78215936043546
Example 2: perl
#!/usr/bin/perl  
  
# Import Math::BigInt module 
use Math::BigInt; 
  
# Specify number 
$num = -78215936043546; 

# Create BigInt object 
$x = Math::BigInt->new($num); 

$x->bneg();

print($x);
Output:
78215936043546
Example 3: perl
#!/usr/bin/perl  
  
# Import Math::BigInt module 
use Math::BigInt; 
  
# Specify number 
$num = 0;
$num1 = NaN;

# Create BigInt object 
$x = Math::BigInt->new($num); 
$y = Math::BigInt->new($num1); 

$x->bneg();
$y->bneg();

print("$x\n");
print($y);
Output:
0
NaN
Comment

Explore