mod method

Big mod(
  1. dynamic y
)

Return a new Big whose value is the value of this Big modulo the value of Big y.

Implementation

Big mod(dynamic y) {
  bool isYgtX;
  var yBig = Big(y);
  var x = this, a = x.s, b = yBig.s;

  if (!yBig.c.isElementIsValid(0)) {
    throw BigError(
      code: BigErrorCode.divByZero,
    );
  }

  x.s = yBig.s = 1;
  isYgtX = yBig.cmp(x) == 1;
  x.s = a;
  yBig.s = b;
  if (isYgtX) return Big(x);

  var tempRm = rm;
  a = dp;
  rm = RoundingMode.roundDown;
  dp = 0;
  x = x.div(yBig);
  dp = a;
  rm = tempRm;
  return sub(x.times(yBig));
}