Perl | Math::BigInt->is_odd() method
Math::BigInt
module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.
is_odd()
method of Math::BigInt
module is used to check whether a number stored as BigInt
object is an odd number or not.
Syntax: Math::BigInt->is_odd()
Parameter: None
Returns: true if the number stored in BigInt object is an odd number, otherwise returns false.
Example 1: Use of Math::BigInt->is_odd()
method
use Math::BigInt;
$n = '89123751682746' ;
$x = Math::BigInt->new( $n );
$isOdd = $x ->is_odd();
if ( $isOdd )
{
print "$n is an odd number\n" ;
}
else
{
print "$n is not an odd number\n" ;
}
$n = '6348762649837957979685908708650797587783' ;
$x = Math::BigInt->new( $n );
$isOdd = $x ->is_odd();
if ( $isOdd )
{
print "$n is an odd number\n" ;
}
else
{
print "$n is not an odd number\n" ;
}
|
Output:
89123751682746 is not an odd number
6348762649837957979685908708650797587783 is an odd number
Example 2: Use of Math::BigInt->is_odd()
method to check whether Octal number is an odd number in decimal or not.
use Math::BigInt;
$octal = 726746425;
$x = Math::BigInt->from_oct( $octal );
$isOdd = $x ->is_odd();
if ( $isOdd )
{
print "$octal (in octal) is an odd number in decimal" ;
}
else
{
print "$octal (in octal) is not an odd number in decimal" ;
}
|
Output:
726746425 (in octal) is an odd number in decimal
Example 3: Use of Math::BigInt->is_odd()
method to check whether a hexadecimal is an odd number in decimal or not.
use Math::BigInt;
$hex = 'Ox112210F4B16C1CB1' ;
$x = Math::BigInt->new( $hex );
$isOdd = $x ->is_odd();
if ( $isOdd )
{
print "$hex (in hexadecimal) is an odd number in decimal" ;
}
else
{
print "$hex (in hexadecimal) is not an odd number in decimal" ;
}
|
Output:
Ox112210F4B16C1CB1 (in hexadecimal) is an odd number in decimal
Last Updated :
03 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...