weiweiwitch
V2EX  ›  问与答

用 js 实现的浮点数值计算,多个平台多种硬件上,相同输入的情况下,结果一致吗?

  •  
  •   weiweiwitch · Apr 10, 2025 · 802 views
    This topic created in 413 days ago, the information mentioned may be changed or developed.
    有个数值计算的功能需要用 js 实现,并通过 nodejs 运行在多种硬件,多个平台上(手机、PC 、服务器)。

    我们能容忍浮点计算出现误差(甚至结果离标准数学计算结果有一定差距),但不能容忍多个端上出现结果不一致的情况( A 机器算出来 0.25 ,B 机器算出来 0.2500001 )。

    目前写 js 的同事使用 demical.js 来实现整个计算过程的。但是性能问题比较大。
    所以想问下,如果改回 number ,是否会有结果不一致的问题?

    计算上,没有太多的复杂运算,加减乘除,最多还有个开平方。
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1244 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:39 · PVG 07:39 · LAX 16:39 · JFK 19:39
    ♥ Do have faith in what you're doing.