Spaceship operator

Spaceship operator

The spaceship operator is a binary relational operator that originated in the Perl programming language. Other languages, such as Ruby and Groovy also support the spaceship operator. It is written <=> . Unlike traditional equality operators, which will return 1 or 0 depending on whether the arguments are equal or unequal, the spaceship operator will return 1, 0, or -1 depending on the value of the left argument relative to the right argument. If the left argument is greater than the right argument, the operator returns 1. If the left argument is less than the right argument, the operator returns -1. If the two arguments are equal, the operator returns 0. In mathematics, this is known as the signum or Sign_function.

The spaceship operator is primarily used for comparisons in sorting.

The spaceship operator takes its name because it looks like a small flying saucer as ASCII art. The term is now commonly used and the operator is referred by the name within the Perl documentation.

This operator is also used in ASCII-based mathematical notation to represent "less than, equal to or greater than", and is synonymous with the symbols ⋛ and ⋚. It can be used to test if the result of a calculation is actually a number.

Example

$a = 5 <=> 7; # $a is set to -1$a = 7 <=> 5; # $a is set to 1$a = 6 <=> 6; # $a is set to 0

External links

* [http://perldoc.perl.org/perlop.html#Equality-Operators-equality-equal-equals-operator%2c-equality Reference to the properties of the operator within perldoc]
* [http://perldoc.perl.org/Math/Complex.html Reference to the actual term within perldoc]


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Relational operator — In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality (e.g., 5 = 5) and inequalities (e.g.,… …   Wikipedia

  • Less-than sign — Computing= The less than sign (>) is an original ASCII charater (hex 3C, decimal 60).Angle bracketsThe less than sign is used for an approximation of the opening angle bracket ( #x27E9;). ASCII does not have angle brackets.Programming languageIn… …   Wikipedia

  • Three-way comparison — In computer science, a three way comparison takes two values A and B belonging to a type with a total order and determines whether A < B, A = B, or A > B in a single operation, in accordance with the mathematical law of trichotomy. Machine level… …   Wikipedia

  • Producciones de The Neptunes — Anexo:Producciones de The Neptunes Saltar a navegación, búsqueda The Neptunes han producido a los más grandes artistas del mundo, han creado y escrito grandes canciones número uno en el Billboard 100. Contenido 1 1999 2 2000 3 2001 …   Wikipedia Español

  • Megazone 23 — Cover to Part 1 DVD release メガゾーン23 (Megazōn Tsū Surī) Genre …   Wikipedia

  • Multiple dispatch — Theories and practice of polymorphism Double dispatch Multiple dispatch Operator overloading Polymorphism in computer science Polymorphism in OOP Subtyping …   Wikipedia

  • List of All That characters — This is a listing of each cast member s most notable and/or recurring characters on the Nickelodeon sketch comedy show All That , accompanied by a brief description of each character as well as each actor s time on the show.(Actors are sorted by… …   Wikipedia

  • The Purple Monster Strikes — Directed by Spencer Gordon Bennet Fred C. Brannon Produced by Ronald Davidson …   Wikipedia

  • Объектно-ориентированное программирование на Python — Объектно ориентированное программирование на Python  программирование на Python с использованием парадигмы ООП: с самого начала Python проектировался как объектно ориентированный язык программирования[1]. Содержание 1 Введение 1.1 …   Википедия

  • Spaceballs — This article is about the film. For the TV series, see Spaceballs: The Animated Series. For other uses, see Spaceball (disambiguation). Spaceballs Theatrical release poster Directed by …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”