最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to compute modulo on BigInts in JS - Stack Overflow

programmeradmin2浏览0评论

Given a BigInt in JS, how do you pute its modulo?

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

edit: the difference between this question and the one linked as similar is that this question only pertains to BigInt which is fairly recent.

Given a BigInt in JS, how do you pute its modulo?

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

edit: the difference between this question and the one linked as similar is that this question only pertains to BigInt https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt which is fairly recent.

Share Improve this question edited Jun 2, 2021 at 17:03 wegry asked Jun 2, 2021 at 16:41 wegrywegry 8,1876 gold badges46 silver badges61 bronze badges 1
  • 2 Use a big int for both operands - 10n % 3n? – jonrsharpe Commented Jun 2, 2021 at 16:43
Add a ment  | 

1 Answer 1

Reset to default 8

Both operands of an arithmetic operation involving a BigInt must be BigInts. In your case:

// BigInt literal
10n % 3n;

// BigInt explicit conversion
10n % BigInt(3);
发布评论

评论列表(0)

  1. 暂无评论