Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "compares less than 0" mean?

Context

While I was reading Consistent comparison, I have noticed a peculiar usage of the verb to compare:

There’s a new three-way comparison operator, <=>. The expression a <=> b returns an object that compares <0 if a < b, compares >0 if a > b, and compares ==0 if a and b are equal/equivalent.

Another example found on the internet (emphasis mine):

It returns a value that compares less than zero on failure. Otherwise, the returned value can be used as the first argument on a later call to get.

One last example, found in a on GitHub (emphasis mine):

// Perform a circular 16 bit compare.
// If the distance between the two numbers is larger than 32767,
// and the numbers are larger than 32768, subtract 65536
// Thus, 65535 compares less than 0, but greater than 65534
// This handles the 65535->0 wrap around case correctly

Of course, for experienced programmers the meaning is clear. But the way the verb to compare is used in these examples is not standard in any standardized forms of English.

Questions*

  • How does the programming jargon sentence "The object compares less than zero" translate into plain English?
  • Does it mean that if the object is compared with0 the result will be "less than zero"?
  • Why would be wrong to say "object is less than zero" instead of "object compares less than zero"?

* I asked for help on English Language Learners and English Language & Usage.

like image 604
q-l-p Avatar asked Nov 26 '17 16:11

q-l-p


People also ask

What is. compare to 0?

The Compare To Zero block compares an input signal to zero. Specify how the input is compared to zero with the Operator parameter. The output is 0 if the comparison is false, and 1 if it is true.

Which of the following is not a comparison operator in C++ language <= ==?

Explanation: The operator =! Is not the comparison operator.

What is the spaceship operator?

PHP in Telugu In PHP 7, a new feature, spaceship operator has been introduced. It is used to compare two expressions. It returns -1, 0 or 1 when first expression is respectively less than, equal to, or greater than second expression.


1 Answers

"compares <0" in plain English is "compares less than zero".

This is a common shorthand, I believe.

So to apply this onto the entire sentence gives:

The expression a <=> b returns an object that compares less than zero if a is less than b, compares greater than zero if a is greater than b, and compares equal to zero if a and b are equal/equivalent.

Which is quite a mouthful. I can see why the authors would choose to use symbols.

like image 145
StoryTeller - Unslander Monica Avatar answered Sep 19 '22 00:09

StoryTeller - Unslander Monica