# Decimal root

`decimal-root` · version 1.0.0 · Money & pricing · free, no key needed

Real nth root (2 to 100) of a decimal string, correctly rounded once to a fixed scale with an explicit mode.

**Use when you need to: square root to 20 decimal places · cube root of a number with rounding · nth root of a decimal correctly rounded.**

## Decide before calling

Read the [versioned contract](/v1/tools/decimal-root/versions/1.0.0) and the supported scope below. Reuse `decimal-root@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `decimal-root@1.0.0` for square root to 20 decimal places. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- square root to 20 decimal places
- cube root of a number with rounding
- nth root of a decimal correctly rounded
- exact square root of a perfect square decimal
- root of a decimal with rounding mode
- high precision square root of 2
- fourth root or fifth root of a decimal
- negative number odd root

## Not supported

- complex roots of negative numbers
- fractional or non integer degrees
- exponentiation or logarithms
- floating point or scientific notation input

## Behavior

- Decimal strings match ^-?(0|[1-9][0-9]*)(\.[0-9]+)?$: no plus sign, exponent, leading zeros, leading or trailing point, whitespace or separators. A JSON number where a decimal string is required is invalid_input (wrong type).
- A decimal string longer than 62 UTF-16 code units -> limit_exceeded, checked before the grammar. Otherwise a grammar failure, more than 60 digits in total, or more than 40 fraction digits -> invalid_input.
- Zero has no sign: "-0", "-0.00" and any all-zero value are zero and are emitted as "0" (canonical) or "0.00" (fixed scale), never "-0".
- value, scale and rounding are required; degree is optional and defaults to 2. degree is a JSON integer 2..100; anything else (1, 101, a string, a float) -> invalid_input.
- The result is the real root of the exact rational value, correctly rounded once to scale fraction digits with the given mode. It is never computed through floating point.
- Exactness: a perfect power (for example sqrt("6.25") = 2.5 at scale 1, cbrt("-27") = -3) gives exact true. A root that is not representable at the requested scale gives exact false, including an exact tie.
- Ties: the true root can lie exactly halfway between two scale-digit neighbours (sqrt("0.25") = 0.5 at scale 0; sqrt("6.25") = 2.5 at scale 0; cbrt("-0.125") = -0.5 at scale 0). The tie modes (half_even, half_up, half_down, half_ceiling, half_floor) then decide as documented. A root a hair above or below a tie is NOT a tie: sqrt("0.2500000000000000000000000000000000000001") at scale 0 rounds to 1 under half_down, and sqrt("0.2499999999999999999999999999999999999999") to 0 under half_up. Detect ties exactly: with r = floor(root * 10^scale) and N = |value| * 10^(scale*degree), the root is a tie iff (2r+1)^degree = 2^degree * N.
- A negative value with an even degree -> not_computable with details.reason "even_root_of_negative". A negative value with an odd degree gives the negative real root; rounding modes then act on the signed result (floor of -1.2599 at scale 2 is -1.26, ceiling is -1.25, up is -1.26, down is -1.25).
- A zero value (including "-0") gives zero at scale digits ("0.00" at scale 2, "0" at scale 0), exact true, never "-0". A negative root that rounds to zero is written without a minus sign.
- rounding "unnecessary" with an irrational or inexact root -> not_computable with details.reason "rounding_necessary".
- A result rounded to scale s is written with exactly s fraction digits (no fraction and no point when s is 0).
- Rounding modes act on the exact rational result and are: half_even (ties to the even neighbour), half_up (ties away from zero), half_down (ties toward zero), half_ceiling (ties toward +infinity), half_floor (ties toward -infinity), up (away from zero), down (toward zero), ceiling (toward +infinity), floor (toward -infinity), unnecessary (any inexact result -> not_computable with details.reason "rounding_necessary").
- Validation order (each vector carries a single fault): input not an object; unknown field; missing required field; field types, ranges and decimal-string limits; scale/rounding pairing; then domain errors (not_computable) last.

## Input

- `value` (string, required): min length 1; max length 62; pattern `^-?(0|[1-9][0-9]*)(\.[0-9]+)?$`; Radicand as a decimal string.
- `degree` (integer, optional): min 2; max 100; Root degree, 2 to 100. Default 2 (square root).
- `scale` (integer, required): min 0; max 40; Fraction digits of the result.
- `rounding` (one of "half_even", "half_up", "half_down", "half_ceiling", "half_floor", "up", "down", "ceiling", "floor", "unnecessary", required): Rounding mode applied to the true root.

## Output

- `value` (string, required): min length 1; max length 100; The root at exactly scale fraction digits (no point when scale is 0).
- `exact` (boolean, required): true when the reported value equals the true root (perfect power).

## Limits

- max decimal chars: 62
- max decimal digits: 60
- max fraction digits: 40
- max scale: 40
- min degree: 2
- max degree: 100

## Example

Request input:

```json
{
  "value": "2",
  "scale": 20,
  "rounding": "half_even"
}
```

Response:

```json
{
  "result": {
    "value": "1.41421356237309504880",
    "exact": false
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "decimal-root",
  "version": "1.0.0",
  "input": {
    "value": "2",
    "scale": 20,
    "rounding": "half_even"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/decimal-root/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"value":"2","scale":20,"rounding":"half_even"}'
```

The machine-readable contract is at [/v1/tools/decimal-root/versions/1.0.0](/v1/tools/decimal-root/versions/1.0.0).

### CLI

```sh
node cli.mjs run decimal-root 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Decimal power](/tools/decimal-power): Raise a decimal string to an integer power exactly, with optional single rounding to a fixed scale.
- [Decimal divide](/tools/decimal-divide): Divide two decimal strings exactly, rounding the quotient once to a fixed scale, and report the exact remainder.
- [Decimal round](/tools/decimal-round): Round a decimal string with an explicit mode to fraction digits, significant digits or a multiple of an increment.
- [Decimal multiply](/tools/decimal-multiply): Multiply two decimal strings exactly, optionally rounding the product once to a fixed scale with a chosen mode.
- [Decimal expression evaluate](/tools/decimal-expression-evaluate): Evaluate a decimal arithmetic expression exactly with variables, abs, min, max and round, rounding once at the end.
- [Decimal to fraction](/tools/decimal-to-fraction): Convert a decimal or repeating decimal like 0.41(6) to a reduced fraction, or the closest fraction under a cap.
