3 ms·
No, it could be used for any type. It would be equivalent to (a<b)&&(a==b)&&(a>b), but would be most useful for floating point, where this operator would evalua
by idea1434 9y ago
No, it could be used for any type. It would be equivalent to (a<b)&&(a==b)&&(a>b), but would be most useful for floating point, where this operator would evaluate to false if a or b is NaN.
- pleasecalllater 9y agoNope, this operator will always evaluate to false. Show me any pair of numbers, which is not NaN, which will be at the same time, equal, smaller, and greater. Of course I can imagine such a set, and operations... (I have a little bit of a mathematical background) but for programming it will be quite useless. Why not `is_nan()` insted?
- daemin 9y agoNo, the operator is like the same operator in Ruby. You define an operator<=> for one or two types and then whenever you use one of the normal comparison operators in code (say a < b), the compiler replaces it with a<=>b < 0.