【发布时间】:2019-01-22 20:04:45
【问题描述】:
我正在尝试使用数学库的一些功能,例如(pow、floor 等)。但是,当我尝试将它们与这样的 Big Int 一起使用时......
let x = Math.pow(100n, 100n);
我明白了
TypeError:无法将 BigInt 值转换为数字
当然我可以自己实现,比如...
const BigMath ={
pow(num, pow){
let total;
for(let i = 0; i < pow; i++){
if(!total) total = num;
else total = total * num;
}
return total;
}
}
let x = BigMath.pow(100n, 100n);
但我不想返回并重新实现所有功能。特别是因为从我的实现看来,它应该能够处理它没有问题。
那么如何使用 BigInt 处理 Math.*?
【问题讨论】:
标签: javascript bigint