add

Adds another value to the receiver and returns the exact decimal sum.

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

0.1 + 0.2; // 0.30000000000000004

const x = Arith.from("0.1");
const y = x.add("0.2");
y.toString(); // "0.3"

// Chain additions without converting through JavaScript numbers.
Arith.from("0.7").add(x).add(y).toString(); // "1.1"

// Use the (string, base) overload when the addend is written in another base.
x.add("0.1", 8).toString(); // "0.225"

// The receiver is not mutated.
x.toString(); // "0.1"

// Use the static helper when no method chain is needed.
Arith.add("1", "2").toString(); // "3"
Arith.add("0.1", "0.2").toString(); // "0.3"

API Reference

Signature

add(n: ArithValue): ArithInstance;
add(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.

Throws

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

Agent Contract

FieldValue
Kindinstance method and static helper
Canonical nameadd
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadYes
Configuration dependenciesNone
Related methodsNone

Agent Notes

  • Do not use JavaScript arithmetic operators on Arith values.
  • Import with import { Arith } from "@teakit/arith"; default imports are unsupported.
  • Use Arith.from(...) to create values. Do not generate new Arith(...) or Arith(...).
  • 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.