您的第一个计算超过Number.MAX_SAFE_INTEGER
,这意味着无法准确表示。BigInt
相反,使用s将产生正确的结果。
console.log("Is 450000005 * 450000005 (x * x) safe?",
Number.isSafeInteger(450000005 * 450000005));
x = 450000005n;
y = 225000002n;
n = x * x - 4n * y * y;
m = (x - 2n * y) * (x + 2n * y);
console.log(n.toString(), m.toString());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句