珀尔 |数学::BigInt->bone() 方法
Perl 中的Math::BigInt
模块提供了表示具有任意精度和重载算术运算运算符的整数的对象。
Math::BigInt
模块的bone()方法用于创建一个值为 1 的新对象,如果用于现有对象,则将其设置为 1。
Syntax: Math::BigInt->bone()
Parameter:
plus or minus: to set the sign of one as ‘+’ or ‘-‘
Returns: object with value one
示例 1:
#!/usr/bin/perl
# Import Math::BigInt module
use Math::BigInt;
# Create a BigInt object
$x = Math::BigInt->bone();
# Object created with bone()
print("$x\n");
# Create a BigInt object
$x = Math::BigInt->bone('-');
# Object created with bone()
print("$x");
输出:
1
-1
示例 2:
#!/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->bone();
# Object after function call
print("After function call: $x");
输出:
Before function call: 78215936043546
After function call: 1
示例 3:
#!/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->bone('-');
# Object after function call
print("After function call: $x");
输出:
Before function call: 78215936043546
After function call: -1