comparedTo

Compare two values and return ordering.

Human Summary

Use it when you need tri-state ordering instead of a boolean predicate.

AI Contract

FieldValue
Kindinstance method
Canonical namecomparedTo
AliasesNone
Mutates receiverNo
Returns`1
Accepts (string, base) overloadYes
Configuration dependenciesSTRICT
Related methodseq, gt, lt

Signature

comparedTo(n: ArithValue): 1 | -1 | 0 | null;
comparedTo(n: string, base: number): 1 | -1 | 0 | null;

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 1 if greater, -1 if less, 0 if equal, or null if either side is NaN.

Behavior

  • Converts the argument with new Arith(n, base).
  • Returns null if either value is NaN.
  • Does not mutate either value.

Examples

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

new Arith("3").comparedTo("2"); // 1

Errors

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

Agent Notes

  • Use comparison methods instead of JavaScript comparison 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