浮点sqrt()函数是否保证顺序关系 [英] Does floating point sqrt() function guarantee order relation

查看:99
本文介绍了浮点sqrt()函数是否保证顺序关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

given two floating point number x and y, suppose all floating point arithmetic conforming the IEEE754 standard, and a certain implementation of square root function sqrt(),

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

让a,b是两个(精确的)实数,x = op(a),y = op(b),其中op()表示将实数舍入为浮点表示形式.然后是以下问题:(*表示浮点乘法)

Let a, b are two (precise) real number, and x = op(a), y = op(b), where op() denotes rounding a real number to its floating point representation. Then the following question: (* means floating point multiplication)

  1. 如果a< b,sqrt(x)< = sqrt(y)是否必须成立?
  2. 如果sqrt(x)* sqrt(x)< sqrt(y)* sqrt(y),是否确实必须满足< = b.

如果对于上述部分或全部答案为否,则

If to some or all of the above, the answer is NO, then

  • 您知道任何保证1和2的sqrt()实现.
  • 给定一个将实数截断为浮点数的舍入规则,您知道任何保证3和4的sqrt()实现.

推荐答案

IEEE 754要求符合标准的实现提供平方根,并且运算必须从小数点转换为正确舍入的浮点数: >

IEEE 754 requires that conforming implementations provide square root and operations to convert from decimal to floating-point that are correctly rounded:

除以下所述外,本标准的所有符合性实现均应为所有受支持的算术格式提供本节中列出的操作.返回此标准指定的数值结果的每个计算操作都应像首先执行产生无穷精度且范围无限制的中间结果一样执行,然后在必要时将该中间结果四舍五入以适合目标格式…

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…

舍入模式通常用于舍入到最接近的可表示值.如果出现平局,则用低位四舍五入到该值.这样的变体将领带从零舍入.

The rounding mode used most commonly rounds to the nearest representable value. In case of a tie, it rounds to the value with the even low bit. A variant on that rounds ties away from zero.

关于问题1,假设x< y,但sqrt(x)> sqrt(y).由于平方根是单调的,因此sqrt(x)必须比sqrt(y)更接近y的数学平方根,或者sqrt(y)必须比sqrt(x)更接近x的数学平方根.因此,这将违反四舍五入规则.

Regarding question 1, suppose x < y but sqrt(x) > sqrt(y). Since square root is monotonic, then either sqrt(x) must be closer to the mathematical square root of y than sqrt(y) is or sqrt(y) must be closer to the mathematical square root of x than sqrt(x) is. So this would violate the rounding rules.

其他舍入规则在特定方向上四舍五入到最接近的数字,朝+无限,朝-无限或朝零之一. sqrt结果混乱也将违反这些舍入规则.

Other rounding rules rounding to the nearest number in a particular direction, one of toward +infinity, toward −infinity, or toward zero. Disordered sqrt results would violate those rounding rules too.

请注意,许多平台将声称使用IEEE 754格式,但这并不意味着它们符合IEEE 754的操作规则,包括平方根以及从十进制到浮点的转换.

Note that many platforms will claim to use IEEE 754 format, but that does not mean they conform to IEEE 754 rules for operations, including square root and conversion from decimal to floating-point.

问题2是相同的.

问题3具有相同的推理(两次应用:op是弱单调的,而sqrt是弱单调的),前提是 a b 是非负的(或者很小,即使 a [或 b ]为负,x [或y]为零),这是由于在转换).否则,您可能会有 a < b ,但sqrt(x) <= sqrt(y)不成立,因为x是NaN,且不小于等于.

Question 3 holds with identical reasoning (applied twice: op is weakly monotonic, and sqrt is weakly monotonic) subject to the proviso that a and b are non-negative (or are so small in magnitude that x [or y] zero even though a [or b] is negative, due to rounding during the conversion). Otherwise, you could have a < b, but sqrt(x) <= sqrt(y) does not hold because x is a NaN, which is not less than or equal to anything.

问题4成立,现在应用了三次弱的单调性.

Question 4 holds, now with weak monotonicity applied three times.

这篇关于浮点sqrt()函数是否保证顺序关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆