user541686
user541686

Reputation: 210755

What do these operators do in D 2.0: <>= !<>= !<= !>=

What do these operators do in D 2.0:

Upvotes: 7

Views: 365

Answers (3)

Ralph Tandetzky
Ralph Tandetzky

Reputation: 23650

They are comparison operators in D, just like ==, < and >=. In D the value nan (not a number) is taken into account. Two floating point numbers cannot only compare less, equal or greater, but also unordered, which is the case, if one of the comparands is nan.

Hence <>= means less, equal or greater. In other words <>= means ordered.

The comparison operators starting with an ! return exactly the opposite of their counterpart without the !. In particular, all of them evaluate to true, if one of the comparands is nan.

Here's a full list of all comparison operators in D:

  • ==
  • !=
  • >
  • >=
  • <
  • <=
  • !<>=
  • <>
  • <>=
  • !<=
  • !<
  • !>=
  • !>
  • !<>

You can find this list in the D documentation. The behaviours of all of these operators is explained there.

Upvotes: 1

BCS
BCS

Reputation: 78683

The long answer:

When dealing with floating point, two values will compare as one of A<B, A=B, A>B or unordered (if one is NaN).

The operators represent every interesting (non constant) row in the truth table. They can be interpreted as testing true for each of the cases for which the operator has the corresponding char, unless it has ! in which case the value is inverted.

Upvotes: 2

Marcelo Cantos
Marcelo Cantos

Reputation: 186098

They are used for values that could be unordered, such as NaN for floats and doubles. 1 <>= NaN evaluates to false, whereas x <>= y evaluates to true for any pair of numbers, as long as neither number is NaN. The other operators you mention work the same, mutatis mutandis.

Upvotes: 7

Related Questions