如何在 JS 中计算 BigInts 的模数

How to compute modulo on BigInts in JS

在 JS 中给定一个 BigInt,你如何计算它的模数?

10n % 3 // Uncaught TypeError: can't convert BigInt to number

编辑:这个问题与类似链接的问题之间的区别在于,这个问题只与 BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt 有关,这是最近的问题。

涉及 BigInt 的算术运算的两个操作数都必须是 BigInt。你的情况:

// BigInt literal
10n % 3n;

// BigInt explicit conversion
10n % BigInt(3);