ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Double in Kotlin is a built-in class representing a double-precision 64-bit IEEE 754 floating-point number. In Kotlin’s unified type system, there are no primitive types at the language level; everything is an object, allowing Double to possess member functions and properties. To maintain performance, the Kotlin compiler optimizes Double to the JVM primitive double at runtime whenever possible.
Technical Specifications
- Memory Size: 64 bits (8 bytes)
- Bit Layout: 1 sign bit, 11 exponent bits, and 52 significand (mantissa) bits.
- Maximum Value:
Double.MAX_VALUE(approx.1.7976931348623157E308) - Minimum Non-Zero Value:
Double.MIN_VALUE(approx.4.9E-324)
Syntax and Instantiation
By default, the Kotlin compiler infers any fractional literal as aDouble. Scientific notation is natively supported and also inferred as Double.
Float, an f or F suffix is required. Without it, the literal is strictly evaluated as a Double.
JVM Representation and Boxing
While Kotlin treatsDouble as a class, it compiles down to the Java primitive double to avoid memory overhead. However, if a Double is declared as nullable (Double?) or is used within a generic context (such as List<Double>), the compiler performs autoboxing, mapping it to the java.lang.Double reference type on the JVM.
Type Conversion
Kotlin enforces strict type safety and does not support implicit widening conversions. Types with smaller memory footprints or different representations (likeInt or Float) cannot be implicitly assigned to a Double. Explicit conversion functions must be invoked.
Special IEEE 754 Values
TheDouble companion object provides constants for special floating-point states defined by the IEEE 754 standard:
Equality and Comparison Rules
Equality evaluation forDouble in Kotlin strictly depends on the static type of the operands being compared.
IEEE 754 Comparison
When the static type of the operands isDouble or Double?, structural equality (==) performs standard IEEE 754 floating-point comparison. Under these rules, positive and negative zero are considered equal, and NaN is not equal to anything, including itself.
Total Order Comparison
When the static type of the operands isAny, Comparable, or a generic type parameter, Kotlin abandons IEEE 754 rules and applies total order comparison. This ensures predictable behavior when floating-point numbers are used as keys in maps or sorted in collections. Under total order rules, NaN is considered equal to itself and greater than POSITIVE_INFINITY, and -0.0 is considered strictly less than 0.0.
Precision Limitations
BecauseDouble relies on base-2 fractions, it cannot perfectly represent all base-10 fractional values. This leads to standard floating-point arithmetic inaccuracies during evaluation.
Master Kotlin with Deep Grasping Methodology!Learn More





