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) → BigInt

This operator-modulo operator of BigInt euclidean modulo operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe BigInt divisor


✐ Examples

1 Calculate modulo of positive dividend and divisor

In this example,

  1. We define a positive dividend BigInt dividend with a value of 10 and a positive divisor BigInt divisor with a value of 3.
  2. We use the `%` operator to calculate the remainder of the division of dividend by divisor.
  3. 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,

  1. We define a negative dividend BigInt dividend with a value of -10 and a positive divisor BigInt divisor with a value of 3.
  2. We use the `%` operator to calculate the remainder of the division of dividend by divisor.
  3. 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,

  1. We define a positive dividend BigInt dividend with a value of 10 and a negative divisor BigInt divisor with a value of -3.
  2. We use the `%` operator to calculate the remainder of the division of dividend by divisor.
  3. 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.