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

# Swift Double

`Double` is a standard library structure in Swift that represents a 64-bit, double-precision, floating-point number. It conforms to the IEEE 754 specification for floating-point arithmetic and provides a precision of at least 15 decimal digits.

Because of its higher precision compared to the 32-bit `Float` type, Swift designates `Double` as the default inferred type for all floating-point literals.

## Syntax and Type Inference

When a floating-point literal is assigned to a variable or constant without an explicit type annotation, the Swift compiler automatically infers it as a `Double`.

```swift theme={"dark"}
// Implicit type inference
let inferredValue = 3.141592653589793 // Type is Double

// Explicit type annotation
let explicitValue: Double = 2.718281828459045

// Scientific notation literal
let scientificValue: Double = 1.25e-4 // Represents 0.000125

// Hexadecimal floating-point literal
let hexValue: Double = 0xFp2 // Represents 15 * 2^2 (60.0)
```

## Technical Characteristics

* **Memory Footprint:** 64 bits (8 bytes).
* **Significand Precision:** 53 bits (approximately 15 to 17 decimal digits).
* **Exponent Range:** 11 bits, allowing values from approximately `±2.23 × 10^-308` to `±1.79 × 10^308`.
* **Empty Initializer:** Invoking the empty initializer (`Double()`) evaluates to `0.0`. Note that Swift enforces definite initialization; declaring a variable without an assignment (e.g., `var x: Double`) leaves it uninitialized, and attempting to access it will result in a compile-time error.

## Special Values

Conforming to the IEEE 754 standard, `Double` includes static properties for representing non-standard numeric states:

```swift theme={"dark"}
let positiveInf: Double = .infinity      // Represents positive infinity
let negativeInf: Double = -.infinity     // Represents negative infinity
let notANumber: Double = .nan            // Represents an undefined result (Not a Number)
let zeroValue: Double = .zero            // Represents 0.0
let piValue: Double = .pi                // Represents the mathematical constant Pi
```

You can evaluate these states using built-in boolean properties:

```swift theme={"dark"}
let value: Double = 0.0 / 0.0

let isNaN = value.isNaN           // true
let isInfinite = value.isInfinite // false
let isFinite = value.isFinite     // false
let isZero = value.isZero         // false
```

## Type Conversion

Swift generally requires explicit type conversion when interacting with different numeric types, such as `Int` or `Float`. However, as of Swift 5.5 (SE-0307), the compiler supports implicit conversion between `Double` and `CGFloat`, allowing them to be used interchangeably without explicit casting.

```swift theme={"dark"}
import CoreGraphics

let integerValue: Int = 42
let floatValue: Float = 9.99
let cgFloatValue: CGFloat = 15.5

// Explicit conversion required for Int and Float
let doubleFromInt = Double(integerValue)
let doubleFromFloat = Double(floatValue)

// Implicit conversion supported for CGFloat
let doubleFromCGFloat: Double = cgFloatValue
let cgFloatFromDouble: CGFloat = doubleFromInt

// Explicit conversion from Double to Int
let doubleValue: Double = 10.75
let truncatedInt = Int(doubleValue) // Evaluates to 10 (truncates toward zero)
```

## Key Protocol Conformances

`Double` implements several core Swift protocols that dictate its behavior in the type system:

* **`FloatingPoint` & `BinaryFloatingPoint`:** Provides the foundational floating-point operations, radix definitions, and IEEE 754 behaviors.
* **`ExpressibleByFloatLiteral` & `ExpressibleByIntegerLiteral`:** Allows initialization directly from numeric literals.
* **`Hashable` & `Equatable`:** Enables use as dictionary keys and allows equality comparisons (`==`, `!=`).
* **`Comparable`:** Enables relational comparisons (`<`, `>`, `<=`, `>=`).
* **`Codable`:** Allows serialization and deserialization to formats like JSON or Property Lists.

<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 Swift 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>
