浮点数sqrt()函数是否保证顺序关系

Does floating point sqrt() function guarantee order relation

给定两个浮点数x和y,假设所有的浮点运算都符合IEEE754标准,以及平方根函数sq​​rt()的某种实现,

  1. 如果 x < y,sqrt(x) <= sqrt(y) 是否成立?
  2. 如果 sqrt(x) < sqrt(y),x <= y 必须成立吗?

设a、b是两个(精确的)实数,x = op(a), y = op(b),其中op()表示将实数四舍五入为浮点数。那么下面的问题:(*表示浮点乘法)

  1. 如果 a< b,sqrt(x) <= sqrt(y) 是否成立?
  2. 如果 sqrt(x)*sqrt(x) < sqrt(y)*sqrt(y),a <= b 是否成立。

如果以上的部分或全部答案是否定的,那么

IEEE 754 要求符合标准的实现提供平方根和将十进制转换为浮点数的运算正确舍入:

All conforming implementations of this standard shall provide the operations listed in this clause for all supported arithmetic formats, except as stated below. Each of the computational operations that return a numeric result specified by this standard shall be performed as if it first produced an intermediate result correct to infinite precision and with unbounded range, and then rounded that intermediate result, if necessary, to fit in the destination’s format…

舍入模式最常用舍入到最接近的可表示值。在平局的情况下,它四舍五入到具有更低位的值。该回合的变体与零相关。

关于问题 1,假设 x < ysqrt(x) > sqrt(y)。由于平方根是单调的,因此 sqrt(x) 必须比 sqrt(y) 更接近 y 的数学平方根,或者 sqrt(y) 必须更接近 sqrt(y) 的数学平方根=10=] 而不是 sqrt(x)。所以这会违反舍入规则。

其他舍入规则在特定方向舍入到最接近的数字,朝 + 无穷大、朝 - 无穷大或朝零之一。无序的 sqrt 结果也会违反这些舍入规则。

请注意,许多平台会声称使用 IEEE 754 格式,但这并不意味着它们符合 IEEE 754 运算规则,包括平方根和从十进制到浮点数的转换。

问题 2 相同。

问题 3 具有相同的推理(应用两次:op 是弱单调的,sqrt 是弱单调的),条件是 ab 是非负的(或者幅度很小以至于 x [或 y] 为零,即使 a [或 b] 为负数,由于转换期间的舍入)。否则,您可能 a < b,但 sqrt(x) <= sqrt(y) 不成立,因为 x 是一个 NaN,它是不小于或等于任何值。

问题 4 成立,现在应用了 3 次弱单调性。