> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Greater Than

The `>` (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.

```kotlin theme={"dark"}
val a = 10
val b = 5

// Standard operator syntax
val isGreater = a > b

// Compiler-translated equivalent
val isGreaterTranslated = a.compareTo(b) > 0
```

## 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:

1. Implementing the `Comparable<T>` interface (which inherently provides the `operator` modifier).
2. Defining a standalone `operator fun compareTo` as a member or extension function.

```kotlin theme={"dark"}
// Method 1: Implementing Comparable<T>
class Measure(val magnitude: Int) : Comparable<Measure> {
    override fun compareTo(other: Measure): Int {
        return this.magnitude.compareTo(other.magnitude)
    }
}

// Method 2: Standalone operator function
class Weight(val kg: Double) {
    operator fun compareTo(other: Weight): Int {
        return this.kg.compareTo(other.kg)
    }
}
```

## Return Value Contract

The underlying `compareTo` 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:

* `NaN` is considered equal to itself and strictly greater than `POSITIVE_INFINITY`.
* `0.0` is considered strictly greater than `-0.0`.

```kotlin theme={"dark"}
// IEEE 754 primitive comparison
val primitiveNanGreater = Float.NaN > Float.POSITIVE_INFINITY // Evaluates to false
val primitiveZeroGreater = 0.0 > -0.0                         // Evaluates to false

// Generic Comparable comparison
val genericNan: Comparable<Float> = Float.NaN
val genericZero: Comparable<Double> = 0.0

val genericNanGreater = genericNan > Float.POSITIVE_INFINITY  // Evaluates to true
val genericZeroGreater = genericZero > -0.0                   // Evaluates to true
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
