Skip to content
Related Articles

Related Articles

Perl | Math::BigInt->bneg() 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.

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:




#!/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:




#!/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:




#!/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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!