gpt4 book ai didi

webassembly - 为什么 webassembly 有平方根操作码?

转载 作者:行者123 更新时间:2023-12-03 16:19:42 27 4
gpt4 key购买 nike

Webassembly 仅提供一种更高级的浮点运算:平方根。
它没有任何其他通常在 CPU 中实现的功能,例如幂和三角函数,官方常见问题解答中解释了这一基本原理:

WebAssembly doesn’t include its own math functions like sin, cos, exp,pow, and so on. WebAssembly’s strategy for such functions is to allowthem to be implemented as library routines in WebAssembly itself (notethat x86’s sin and cos instructions are slow and imprecise and aregenerally avoided these days anyway). Users wishing to use faster andless precise math functions on WebAssembly can simply select a mathlibrary implementation which does so.


这就引出了一个问题,如果平方根有什么特别之处可以证明它有异常(exception)。它对距离计算很有用,但是它是否比其他类型的幂或指数出现得更频繁?它在 CPU 上是否特别快并且他们想利用它?
如果我们做两桶函数,
  • 第一个是加法、乘法、除法和余数和
  • 第二个是幂、三角函数及其反演

  • 那他们为什么把平方根放在第一位呢?
    编辑:我刚刚意识到 sqrt 的特殊之处在于可以通过将指数向右移动 1 来找到近似值。确切的结果仍然需要找到尾数的平方根,这仍然是一个交互过程。但是,正如 Olsonist 指出的那样,这种领先优势可能使 sqrt 足够好,可以保证包含在 IEEE 所需的操作中。
    还有 sqrt(x*x)=x的属性所有 x其中 x*x不会上溢或下溢,这对于可能涉及舍入 ( see this SO answer ) 的操作来说是不寻常的。

    最佳答案

    IEEE 754-2008 是 WebAssembly 的要求,sqrt 是 IEEE 754-2008 的要求,而 sin、cos、... 不是 IEEE 754-2008 的要求。他们是 recommended但不是必需的。

    关于webassembly - 为什么 webassembly 有平方根操作码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65655125/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com