The `sign` property returns the sign of a given big integer.
The syntax of BigInt.sign property is:
int sign
This sign property of BigInt returns the sign of this big integer.
BigInt.sign returns value of type int
.
In this example,
num1
and num2
, initialized with 10 and -15 respectively.sign
property to check the sign of these numbers.void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(-15);
int sign1 = num1.sign;
int sign2 = num2.sign;
print('Sign of 10: $sign1');
print('Sign of -15: $sign2');
}
Sign of 10: 1 Sign of -15: -1
In this example,
num
, initialized with 0.sign
property to check the sign of zero.void main() {
BigInt num = BigInt.from(0);
int sign = num.sign;
print('Sign of 0: $sign');
}
Sign of 0: 0
In this example,
num
, by parsing the string '123456789012345678901234567890'.sign
property to check the sign of this large number.void main() {
BigInt num = BigInt.parse('123456789012345678901234567890');
int sign = num.sign;
print('Sign of a large number: $sign');
}
Sign of a large number: 1
In this Dart tutorial, we learned about sign property of BigInt: the syntax and few working examples with output and detailed explanation for each example.