pow

Raises the receiver to an integer exponent or an explicit fraction-string exponent.

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

Math.pow(0.7, 2); // 0.48999999999999994

const x = Arith.from("0.7");
x.pow(2).toString(); // "0.49"

// Negative integer exponents use division precision settings.
Arith.from("3").pow(-2).toString(); // "0.11111111111111111111"

// Explicit fraction-string exponents are accepted in the exponent position.
Arith.from("9").pow("1/2").toString(); // "3"
Arith.from("32").pow("2/5").toString(); // "4"
Arith.from("16").pow("-1/2").toString(); // "0.25"

// Negative bases with non-integer fraction exponents follow decimal.js semantics.
Arith.from("-8").pow("1/3").toString(); // "NaN"
Arith.from("-8").pow("3/1").toString(); // "-512"

// Use the modulus argument for modular exponentiation.
Arith.from("4").pow("13", "497").toString(); // "445"
Arith.from("4").pow("2/1", "3").toString(); // "1"

// Use the static helper when no method chain is needed.
Arith.pow("2", "10").toString(); // "1024"
Arith.pow("9", "1/2").toString(); // "3"

API Reference

Signature

pow(n: ArithValue, m?: ArithValue): ArithInstance;
pow(n: number, m?: ArithValue): ArithInstance;

Parameters

ParameterTypeRequiredNotes
n`ArithValuenumber`Yes
mArithValueNoOptional modulus. Only valid with integer exponents or fraction strings that normalize to an integer.

Returns

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

Throws

  • Throws if n is a finite non-integer.
  • Throws if n is an invalid fraction string.
  • Throws if a non-integer fraction exponent is used with m.
  • Throws if n or m is invalid while STRICT is true.

Agent Contract

FieldValue
Kindinstance method and static helper
Canonical namepow
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesDECIMAL_PLACES, ROUNDING_MODE, POW_PRECISION
Related methodsfromRatio, ratio, sqrt, mod

Agent Notes

  • Use pow("p/q") only when the exponent position intentionally carries an exact ratio string.
  • Do not generate Arith.from("p/q"); fraction strings are only valid in fromRatio(...) and the pow(...) exponent position.
  • Do not use modulo with non-integer fraction exponents.
  • For negative bases and non-integer fraction exponents, expect NaN; do not rewrite pow("1/3") to cbrt().
  • 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.