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

# C++ long double

The `long double` type in C++ is a fundamental, built-in floating-point data type designed to provide a precision at least as strict as that of a standard `double`. It represents the most precise floating-point format natively supported by the compiler and target architecture. According to the C++ Standard, the size and precision guarantees follow a strict ordering: `sizeof(float) <= sizeof(double) <= sizeof(long double)`.

## Implementation-Defined Sizing

The exact bit-width, precision, and memory layout of `long double` are implementation-defined and highly dependent on the compiler, operating system, and hardware architecture:

* **x86/x86-64 (Linux/macOS):** Typically implemented as the x87 80-bit extended precision format. Due to memory alignment requirements, `sizeof(long double)` usually evaluates to 12 or 16 bytes, even though only 10 bytes (80 bits) are utilized for the significand and exponent.
* **x86/x86-64 (Windows/MSVC):** Implemented as a 64-bit IEEE 754 double-precision float. On this toolchain, `long double` is identical to `double` in both size (`sizeof(long double) == 8`) and precision.
* **ARM64 / Specific UNIX platforms:** Often implemented as a 128-bit IEEE 754 quadruple-precision floating-point format (`sizeof(long double) == 16`).

## Syntax and Literals

To explicitly declare a `long double` literal, append the `L` or `l` suffix to a floating-point number. Without the suffix, the compiler treats the literal as a standard `double`, which may result in a silent loss of precision during initialization before the assignment occurs.

```cpp theme={"dark"}
// Explicit long double literals using the 'L' suffix
long double pi_val = 3.141592653589793238462643383279502884L;
long double planck_const = 6.62607015e-34L; 

// Warning: Literal is parsed as a double; precision is truncated before assignment
long double truncated_val = 3.141592653589793238462643383279502884; 
```

## Standard Library Interfaces

### Type Traits and Limits

The `<limits>` header provides compile-time introspection for the specific characteristics of `long double` on the target platform.

```cpp theme={"dark"}
#include <iostream>
#include <limits>

int main() {
    // Number of base-10 digits that can be represented without change
    std::cout << std::numeric_limits<long double>::digits10 << '\n';
    
    // Maximum finite value representable by the type
    std::cout << std::numeric_limits<long double>::max() << '\n';
    
    // Difference between 1.0 and the next representable value
    std::cout << std::numeric_limits<long double>::epsilon() << '\n';
    
    return 0;
}
```

### Mathematical Functions

The `<cmath>` header provides overloaded mathematical functions for `long double`. In modern C++, the standard functions (e.g., `std::sin`, `std::exp`) are overloaded to accept `long double` natively, but the C-style `l`-suffixed functions remain available.

```cpp theme={"dark"}
#include <cmath>

long double val = 2.0L;

// C++ overloaded standard math function
long double result1 = std::sqrt(val); 

// C-style explicit long double math function
long double result2 = std::sqrtl(val); 
```

### Formatted I/O

When using C++ streams (`<iostream>`), `long double` is handled automatically via operator overloading. However, when interfacing with C-style I/O (`<cstdio>`), the `L` length modifier must be used in conjunction with a floating-point conversion specifier (`f`, `e`, `g`).

```cpp theme={"dark"}
#include <cstdio>

long double large_frac = 0.1234567890123456789L;

// %Lf is strictly required for long double in printf/scanf
std::printf("%.19Lf\n", large_frac); 
```

<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 C++ 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>
