mul

Multiplies the receiver by another value and returns the exact decimal product.

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

0.6 * 3; // 1.7999999999999998

const x = Arith.from("0.6");
const y = x.mul(3);
y.toString(); // "1.8"

// Chain multiplication without converting through JavaScript numbers.
Arith.from("7e+5").mul(y).toString(); // "1260000"
Arith.from("7e+500").mul(y).toString(); // "1.26e+501"

// Use the (string, base) overload when the multiplier is written in another base.
x.mul("-a", 16).toString(); // "-6"

// Use the static helper when no method chain is needed.
Arith.mul("1.5", "4").toString(); // "6"
Arith.mul("1000000", "0.0015").toString(); // "1500"

API Reference

Signature

mul(n: ArithValue): ArithInstance;
mul(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 namemul
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadYes
Configuration dependenciesNone
Related methodsadd, div

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.