Skip to main content

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.

The > (greater than) operator is a binary relational operator that evaluates whether the left operand is strictly greater than the right operand, yielding an untyped boolean value (true or false). In Go, the > operator requires operands to be of an ordered type. Because Go enforces strict typing, the operands must adhere to one of the following typing rules:
  • Same Concrete Type: Both operands are of the exact same typed ordered type. Implicit type coercion between different concrete types (e.g., int32 and int64) is prohibited and yields a compile-time error.
  • Typed and Untyped: One operand is a typed variable and the other is an untyped constant. This is valid as long as the untyped constant is representable by a value of the typed operand’s type.
  • Both Untyped: Both operands are untyped constants. In this scenario, they are evaluated exactly as untyped mathematical values using arbitrary precision. They do not need to be representable by any concrete Go type (e.g., values that would overflow a float64 can still be compared).

Syntax

result := operand1 > operand2

Supported Ordered Types

The > operator is exclusively defined for types that possess a natural ordering:
  • Integer types (int, int8, uint32, etc.): Evaluates the mathematical integer value.
  • Floating-point types (float32, float64): Evaluates the numeric value according to IEEE-754 standards. +Inf is greater than any finite number. NaN comparisons always evaluate to false.
  • String types: Evaluates lexicographically, comparing the underlying byte values sequentially from left to right.

Unsupported Types

The > operator cannot be used with unordered types. Attempting to use > with booleans, complex numbers, pointers, structs, arrays, slices, maps, channels, or interfaces will result in a compiler error.

Code Examples

// Numeric comparison (same concrete type)
var a int = 10
var b int = 5
isGreater := a > b // true

// Typed variable and untyped constant comparison
var x int32 = 5
isPositive := x > 0 // true (untyped 0 is representable as int32)

// Untyped constant comparison (evaluated exactly with arbitrary precision)
const c1 = 1e1000
const c2 = 1e999
isConstGreater := c1 > c2 // true (evaluated mathematically, no float64 overflow)

// String comparison (lexicographical by byte value)
var s1 string = "zebra"
var s2 string = "apple"
isStringGreater := s1 > s2 // true ('z' byte value 122 > 'a' byte value 97)

// Compile-time error: mismatched types
var y int32 = 10
var z int64 = 5
// invalid operation: y > z (mismatched types int32 and int64)
Master Go with Deep Grasping Methodology!Learn More