此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.5336421T2.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/