TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
> (greater than) operator is a relational operator used to evaluate strict upper-bound inequality between two operands. In Kotlin, it functions as syntactic sugar that the compiler translates into a method call to the compareTo function.
When the compiler encounters a > b, it desugars the expression to evaluate whether the integer returned by compareTo is strictly greater than zero.
Type Requirements
For the> operator to be valid on a given type, the left-hand operand must provide an operator fun compareTo that accepts the right-hand operand’s type and returns an Int. This is structurally achieved in two ways:
- Implementing the
Comparable<T>interface (which inherently provides theoperatormodifier). - Defining a standalone
operator fun compareToas a member or extension function.
Return Value Contract
The underlyingcompareTo function must adhere to a strict mathematical contract, returning:
- A positive integer (
> 0) if the receiver object is strictly greater than the argument. - Zero (
0) if the objects are equal. - A negative integer (
< 0) if the receiver object is less than the argument.
Floating-Point Behavior
When the> operator is used with statically typed Float or Double primitives, the compiler generates JVM bytecodes (fcmpg, dcmpg) that strictly adhere to IEEE 754 floating-point comparison rules. Under these rules, any comparison involving NaN evaluates to false, and -0.0 is evaluated as exactly equal to 0.0.
However, if the operands are boxed or evaluated generically via the Comparable interface, Kotlin delegates to the Float.compareTo and Double.compareTo methods. These methods deviate from IEEE 754 to establish a total order:
NaNis considered equal to itself and strictly greater thanPOSITIVE_INFINITY.0.0is considered strictly greater than-0.0.
Master Kotlin with Deep Grasping Methodology!Learn More





