Dart BigInt sign
Syntax & Examples


BigInt.sign property

The `sign` property returns the sign of a given big integer.


Syntax of BigInt.sign

The syntax of BigInt.sign property is:

 int sign 

This sign property of BigInt returns the sign of this big integer.

Return Type

BigInt.sign returns value of type int.



✐ Examples

1 Check Sign of Positive and Negative Numbers

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with 10 and -15 respectively.
  2. We then use the sign property to check the sign of these numbers.
  3. We print the results to standard output.

Dart Program

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');
}

Output

Sign of 10: 1
Sign of -15: -1

2 Check Sign of Zero

In this example,

  1. We create a BigInt object, num, initialized with 0.
  2. We then use the sign property to check the sign of zero.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(0);
  int sign = num.sign;
  print('Sign of 0: $sign');
}

Output

Sign of 0: 0

3 Check Sign of a Large Number

In this example,

  1. We create a BigInt object, num, by parsing the string '123456789012345678901234567890'.
  2. We then use the sign property to check the sign of this large number.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.parse('123456789012345678901234567890');
  int sign = num.sign;
  print('Sign of a large number: $sign');
}

Output

Sign of a large number: 1

Summary

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.