← All procedures

rational.integerRoot

This function gives the floor of the `k`-th root of `n`: the largest integer `r` with `r^k <= n`. The result is exact. The search starts above the root, from the bit length of `n`, and the Newton steps go down to the root.

CLI
Package
@procedures/rational · README
Path
["rational","integerRoot"]
CLI
mark rational integerRoot --n <string> --k <number>
As data
{"$proc":["rational","integerRoot"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/rational/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["rational","integerRoot"], { n: "<n>", k: 1 });
console.log(JSON.stringify(result));

From the command line

$ mark rational integerRoot --n <string> --k <number>

As data, in a program

{
  "$proc": ["rational", "integerRoot"],
  "input": { "n": "<n>", "k": 1 }
}

Input

FieldTypeRequiredDefaultDescription
nstringyesA value that is not less than `0n`.
knumberyesAn integer index of 1 or more.

Output

The schema does not list fields (string).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "n": {
        "type": "string",
        "pattern": "^-?(0|[1-9][0-9]*)$",
        "x-procedures-codec": "bigint",
        "description": "A value that is not less than `0n`."
      },
      "k": {
        "type": "number",
        "description": "An integer index of 1 or more."
      }
    },
    "required": [
      "n",
      "k"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "string",
    "pattern": "^-?(0|[1-9][0-9]*)$",
    "x-procedures-codec": "bigint"
  }
}