Dart BigInt operator-modulo
Syntax & Examples
BigInt.operator-modulo operator
The `%` operator computes the Euclidean modulo of this BigInt and another BigInt.
Syntax of BigInt.operator-modulo
The syntax of BigInt.operator-modulo operator is:
operator %(BigInt other) → BigIntThis operator-modulo operator of BigInt euclidean modulo operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the BigInt divisor |
✐ Examples
1 Calculate modulo of positive dividend and divisor
In this example,
- We define a positive dividend BigInt
dividendwith a value of10and a positive divisor BigIntdivisorwith a value of3. - We use the `%` operator to calculate the remainder of the division of
dividendbydivisor. - We print the remainder to standard output.
Dart Program
void main() {
BigInt dividend = BigInt.from(10);
BigInt divisor = BigInt.from(3);
BigInt remainder = dividend % divisor;
print('Remainder of 10 modulo 3: $remainder');
}Output
Remainder of 10 modulo 3: 1
2 Calculate modulo of negative dividend and positive divisor
In this example,
- We define a negative dividend BigInt
dividendwith a value of-10and a positive divisor BigIntdivisorwith a value of3. - We use the `%` operator to calculate the remainder of the division of
dividendbydivisor. - We print the remainder to standard output.
Dart Program
void main() {
BigInt dividend = BigInt.from(-10);
BigInt divisor = BigInt.from(3);
BigInt remainder = dividend % divisor;
print('Remainder of -10 modulo 3: $remainder');
}Output
Remainder of -10 modulo 3: -1
3 Calculate modulo of positive dividend and negative divisor
In this example,
- We define a positive dividend BigInt
dividendwith a value of10and a negative divisor BigIntdivisorwith a value of-3. - We use the `%` operator to calculate the remainder of the division of
dividendbydivisor. - We print the remainder to standard output.
Dart Program
void main() {
BigInt dividend = BigInt.from(10);
BigInt divisor = BigInt.from(-3);
BigInt remainder = dividend % divisor;
print('Remainder of 10 modulo -3: $remainder');
}Output
Remainder of 10 modulo -3: 1
Summary
In this Dart tutorial, we learned about operator-modulo operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.