Math::BigInt
Perl中的module提供了代表具有任意精度的整数和重载算术运算符的对象。
is_odd()
的方法Math::BigInt
模块用于检查数字是否存储为BigInt
object是否为奇数。
用法: Math::BigInt->is_odd()
参数:没有
返回:如果存储在BigInt对象中的数字为奇数,则为true,否则返回false。
范例1:用于Math::BigInt->is_odd()
方法
#!/usr/bin/perl
# Import Math::BigInt module
use Math::BigInt;
# Value of n
$n = '89123751682746';
# Create BigInt object
$x = Math::BigInt->new($n);
# Check if the number stored
# in BigInt object is
# an odd number or not
$isOdd = $x->is_odd();
if ($isOdd)
{
print "$n is an odd number\n";
}
else
{
print "$n is not an odd number\n";
}
# Value of n
$n = '6348762649837957979685908708650797587783';
# Create BigInt object
$x = Math::BigInt->new($n);
# Check if the number stored
# in BigInt object is
# an odd number or not
$isOdd = $x->is_odd();
if ($isOdd)
{
print "$n is an odd number\n";
}
else
{
print "$n is not an odd number\n";
}
输出:
89123751682746 is not an odd number 6348762649837957979685908708650797587783 is an odd number
范例2:用于Math::BigInt->is_odd()
检查八进制数是否为十进制的奇数的方法。
#!/usr/bin/perl
# Import Math::BigInt module
use Math::BigInt;
# Octal number represented as string
$octal = 726746425;
# value of octal '726746425' is
# 123456789 in decimal number system
# Create BigInt object
$x = Math::BigInt->from_oct($octal);
# Check whether the Octal
# number stored in BigInt object
# is an odd number or not
# using Math::BigInt->is_odd() method
$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";
}
输出:
726746425 (in octal) is an odd number in decimal
范例3:用于Math::BigInt->is_odd()
一种检查十六进制是否为十进制奇数的方法。
#!/usr/bin/perl
# Import Math::BigInt module
use Math::BigInt;
# Hexadecimal number represented as string
$hex = 'Ox112210F4B16C1CB1';
# Hexadecimal value '0x112210F4B16C1CB1' is
# 1234567890987654321 in decimal number system
# Create BigInt object
$x = Math::BigInt->new($hex);
# Check whether the hexadecimal
# number stored in BigInt object
# is an odd number or not
# using Math::BigInt->is_odd() method
$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";
}
输出:
Ox112210F4B16C1CB1 (in hexadecimal) is an odd number in decimal
相关用法
- perl Math::BigInt->bnan()用法及代码示例
- perl Math::BigInt->bneg()用法及代码示例
- perl Math::BigInt->bone()用法及代码示例
- perl Math::BigInt->bfac()用法及代码示例
- perl Math::BigInt->is_even()用法及代码示例
- perl Math::BigInt->binf()用法及代码示例
- perl Math::BigInt->from_bin()用法及代码示例
- perl Math::BigInt->digit()用法及代码示例
- perl Math::BigInt->bzero()用法及代码示例
- perl Math::BigInt->config()用法及代码示例
- perl Math::BigInt->from_hex()用法及代码示例
- perl Math::BigInt->from_oct()用法及代码示例
注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 Perl | Math::BigInt->is_odd() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。