modulo

Return the remainder after division.

Human Summary

Calculates the remainder using the current modulo mode.

AI Contract

FieldValue
Kindinstance method
Canonical namemodulo
Aliasesmod
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadYes
Configuration dependenciesMODULO_MODE
Related methodsmod

Signature

modulo(n: ArithValue): ArithInstance;
modulo(n: string, base: number): ArithInstance;

Parameters

ParameterTypeRequiredNotes
nArithValueYesValue to convert to Arith before applying the operation.
basenumberNoOnly valid with the (string, base) overload. Must be an integer from 2 through ALPHABET.length.

Returns

Returns a new Arith instance. The receiver is not modified.

Behavior

  • The receiver and argument are converted to Arith values.
  • The receiver is not mutated; a new instance is returned.
  • The quotient used to calculate the remainder is selected by MODULO_MODE.
  • The default mode matches JavaScript remainder sign behavior.

Examples

import { Arith } from "@teakit/arith";

new Arith("7").modulo("4").toString(); // "3"

Errors

  • Throws if base is invalid.
  • Throws if the input value is invalid while STRICT is true.

Agent Notes

  • Do not use JavaScript arithmetic operators on Arith values.
  • Import from @teakit/arith; prefer import { Arith } from "@teakit/arith".
  • Use new Arith(...) to construct values. Do not generate Arith(...) as a function call.
  • Use string inputs for exact decimal values, especially money-like values.
  • Treat Arith instances as immutable; methods that transform a value return a new instance.
  • Do not mutate internal fields such as c, e, s, or _isArith.

See Also