rem static method

Value rem(
  1. Object dividend,
  2. Object? modulus
)

Creates a rem() calculation with the given dividend and modulus.

Each argument must be either a SassNumber, a SassCalculation, an unquoted SassString, or a CalculationOperation.

This automatically simplifies the calculation, so it may return a SassNumber rather than a SassCalculation. It throws an exception if it can determine that the calculation will definitely produce invalid CSS.

This may be passed fewer than two arguments, but only if one of the arguments is an unquoted var() string.

Implementation

static Value rem(Object dividend, Object? modulus) {
  dividend = _simplify(dividend);
  modulus = modulus.andThen(_simplify);
  var args = [dividend, if (modulus != null) modulus];
  _verifyLength(args, 2);
  _verifyCompatibleNumbers(args);
  if (dividend is! SassNumber ||
      modulus is! SassNumber ||
      !dividend.hasCompatibleUnits(modulus)) {
    return SassCalculation._("rem", args);
  }
  var result = dividend.modulo(modulus);
  if (modulus.value.signIncludingZero != dividend.value.signIncludingZero) {
    if (modulus.value.isInfinite) return dividend;
    if (result.value == 0) {
      return result.unaryMinus();
    }
    return result.minus(modulus);
  }
  return result;
}