比较双打是否相等

编程入门 行业动态 更新时间:2024-10-09 00:51:25
本文介绍了比较双打是否相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此fp类型比较代码取自C FAQ。 在宏中使用它的任何问题? / *比较2平等加倍* / #define DBL_ISEQUAL(a,b)(晶圆厂((a) - (b))< =(DBL_EPSILON)*晶圆厂((a))) 在比较2个fp类型中是否涉及相同的问题是否相同 适用于将浮点数与零进行比较?例如。如果(x == 0.0) 被认为有害吗?

解决方案

John Smith写道:

此fp类型比较代码取自C FAQ。 在宏中使用它的任何问题? / *比较2个双倍的相等* / #define DBL_ISEQUAL(a,b)(fabs((a) - (b))< =(DBL_EPSILON)* fabs((a ))) 比较2个fp类型的相同问题是否相同 适用于将浮点数与零进行比较?例如。如果(x == 0.0)认为 有害吗?

根据您的使用方式,您可以根据外部问题高度优化应用程序,例如是否编译额外的 精确模式,或禁用逐渐下溢。

文章< I8Clh.533642

1T2 .401780 @ pd7urf2noJohn Smith< JS **** @ mailwrites:

此fp类型比较代码取自C FAQ。 在宏中使用它的任何问题? / *比较2个双倍的相等* / #define DBL_ISEQUAL(a,b )(晶圆厂((a) - (b))< =(DBL_EPSILON)*晶圆厂((a))) 执行相同的问题,比较2个fp类型是否相等 适用于将浮点数与零进行比较?例如。如果(x == 0.0) 被认为是有害的?

如果你为''a'插入0.0,你会发现两者恰好给出了 相同的结果。另一方面,我认为可以构造 两个浮点数''a''和'b'',结果是不对称的。 但是,这不能阻止你使用宏,当它是不对称的时候你会在浮点运算的郊区。 - dik t。冬天,cwi,kruislaan 413,1098 sj amsterdam,nederland,+ 31205924131 home:bovenover 215,1025 jn amsterdam,nederland; www.cwi.nl/~dik/

This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a))) Do the same issues involved in comparing 2 fp types for equality apply to comparing a float to zero? E.g. is if(x == 0.0) considered harmful?

解决方案

John Smith wrote:

This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a))) Do the same issues involved in comparing 2 fp types for equality apply to comparing a float to zero? E.g. is if(x == 0.0) considered harmful?

Depending on how you use this, you could make your application highly dependent on external issues, such as whether you compile for an extra precision mode, or disable gradual underflow.

In article <I8Clh.533642

1T2.401780@pd7urf2noJohn Smith <JS****@mailwrites:

This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a))) Do the same issues involved in comparing 2 fp types for equality apply to comparing a float to zero? E.g. is if(x == 0.0) considered harmful?

If you insert 0.0 for ''a'' you will see that the two give precisely the same result. On the other hand, I think it is possible to construct two floating point numbers ''a'' and ''b'', where the result is asymmetric. But let that not deter you from using the macro, when it is asymmetric you are in the outskirts of floating-point arithmetic. -- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131 home: bovenover 215, 1025 jn amsterdam, nederland; www.cwi.nl/~dik/

更多推荐

比较双打是否相等

本文发布于:2023-11-30 09:56:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双打

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!