@acransac/sqrt 中文文档教程
sqrt
sqrt 计算公平方根和模平方根。 向它传递一个数字,它就是 Javascript 的标准 Math.sqrt
。 将它与两个整数 a 和 p(p 素数)一起使用以计算 a 模 < em>p。
可以为 Javascript 的 number
范围内的整数或任意精度的 BigInt
计算模平方根。
Installation
sqrt 是一个 npm 包:
$ npm install @acransac/sqrt
它可以通过以下方式卸载:
$ npm uninstall @acransac/sqrt
Usage
import sqrt from '@acransac/sqrt';
sqrt(25); // 5
sqrt(123.45); // 11.110805551354051
sqrt(3, 11); // [5, 6]
sqrt(1267650600228227149696889519974n, 1267650600228229401496703205223n); // [403392878153763115700000692025n, 864257722074466285796702513198n]
API
sqrt(x[,modulo])
x
\| \ modulo
\| \ Default: undefined
- Returns: \
| \ | \ | \
如果只有 x
已提供。 后者应该是一个 number
并且返回一个 number
或 NaN
。 它是 Math.sqrt
。
如果提供了两个参数,则计算 x
模 modulo
的平方根。 x
和 modulo
可以是 number
或 bigint
但它们应该是同一类型。 x
的范围应从 0 到 modulo
。 modulo
应至少为 2 和质数。 这对根按升序返回,整数类型与输入相同。 如果没有根或计算失败或输入无效,则返回 NaN
。 如果 modulo
不是质数,sqrt
要么返回 NaN
要么挂起。
sqrt
sqrt computes common and modular square roots. Pass it a single number and it is Javascript's standard Math.sqrt
. Use it with two integers a and p (p prime) to compute the integer square roots of a modulo p.
Modular square roots can be computed for integers in Javascript's number
range or for arbitrary-precision BigInt
s.
Installation
sqrt is a npm package:
$ npm install @acransac/sqrt
It can be uninstalled with:
$ npm uninstall @acransac/sqrt
Usage
import sqrt from '@acransac/sqrt';
sqrt(25); // 5
sqrt(123.45); // 11.110805551354051
sqrt(3, 11); // [5, 6]
sqrt(1267650600228227149696889519974n, 1267650600228229401496703205223n); // [403392878153763115700000692025n, 864257722074466285796702513198n]
API
sqrt(x[,modulo])
x
\| \ modulo
\| \ Default: undefined
- Returns: \
| \ | \ | \
Compute the common square root if only x
is provided. The latter should be a number
and a number
or NaN
is returned. It is Math.sqrt
.
Compute the square root of x
modulo modulo
if both arguments are provided. x
and modulo
can either be number
s or bigint
s but they should be of the same type. x
should range from 0 to modulo
included. modulo
should be at least 2 and prime. The pair of roots is returned in ascending order with the same integer type as the inputs. If there is no root or the computation failed or the inputs are invalid NaN
is returned. If modulo
is not prime, sqrt
either returns NaN
or hangs.