最好完全避免使用浮点数比较。
It would be best to try to avoid floating point comparison entirely.
为什么需要用单独的宏进行浮点数比较?
Why do you need separate macros for floating point comparisons?
Google提供清单9所示的宏以支持浮点数比较。
Google provides the macros shown in Listing 9 for floating point comparisons.
当然,这并不总是可能的,但您应该意识到要限制浮点数比较。
This is, of course, not always possible, but you should be aware of the limitations of floating point comparison.
通常,不同的中央处理单元 (CPU)和操作环境以不同的方式存储浮点数,简单地比较期望值和实际值是无效的。
Typically, different central processing units (CPUs) and operating environments store floating points differently and simple comparisons between expected and actual values don't work.
当然,结果不一定是有意义的 —— 比如字符串和浮点数的比较就没有意义。
Sure, the result would not necessarily be meaningful -- a string is neither objectively less than nor greater than a float.
具体地说,复数无法与其他数字进行比较了,包括其他复数以及整数、浮点数和长整数。
Specifically, complex Numbers became incomparable to other Numbers, including both other complex Numbers and ints, floats, and longs.
NaN的无序性质使得在比较浮点数时更容易发生错误。
The non-ordered nature of NaN adds further opportunities for error when comparing floating point numbers.
不过这份数据中包含几个引人注目的增强:比较浮点数与整数的性能提高了75%,内建函数的访问性能提高了41%。
However, there are some notable improvements hidden within that overall drop. Float-Integer comparison improved 75%, and builtin function calls improved 41%.
可以看到,对于比较小的2的幂次方,浮点数是非常精确的。
As you can see, floats are pretty accurate for small powers of two.
另外,不能在浮点数、整数和长整数(比如decimal)之间进行比较是非常不方便的。
Moreover, not being able to compare among floats, ints, and longs (or, for example, decimal) would be awkward.
为什么工厂给怪异的结果在比较浮点数?
Why fabs giving weird result while comparing floating point Numbers?
一个平等比较浮点数和双首先将浮动转换为双,然后比较这两个。
An equality comparison between float and double first converts the float to a double and then compares the two.
比较两个单精确度浮点数是否相等;如果相等,则取代其中一值。
Compares two objects for reference equality and, if they are equal, replaces one of the objects.
但要注意,对浮点数字的比较是非常严格的。
Be aware, however, that the comparison of floating-point Numbers is very strict.
要排序的数据类型有很多种,有整数、浮点数、各种结构(根据某个属性进行比较)等。
To sort data type there are many, there is an integer, floating-point Numbers, all kinds of structure (based on a comparison of the properties) and so on.
要排序的数据类型有很多种,有整数、浮点数、各种结构(根据某个属性进行比较)等。
To sort data type there are many, there is an integer, floating-point Numbers, all kinds of structure (based on a comparison of the properties) and so on.
应用推荐