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 long double type in C is a standard scalar floating-point data type designed to provide precision and range greater than or equal to that of a standard double. It represents the maximum floating-point precision natively supported by the compiler and the target hardware architecture.

Memory Representation and Precision

The C standard does not mandate a strict bit-width for long double, only requiring that its precision is at least that of double. Consequently, its memory footprint and IEEE 754 implementation are highly architecture- and compiler-dependent:
  • x86/x86_64 (GCC/Clang on Linux/macOS): Typically implemented as an 80-bit extended-precision format. Due to memory alignment requirements, sizeof(long double) evaluates to 12 or 16 bytes, though only 10 bytes (80 bits) are used for the value.
  • ARM64/AArch64: Often implemented as a 128-bit quadruple-precision floating-point format (sizeof(long double) == 16).
  • MSVC (Windows): Implemented as a 64-bit standard double-precision format. On this compiler, long double is strictly identical to double (sizeof(long double) == 8).

Syntax and Literals

By default, floating-point literals in C are of type double. To explicitly declare a long double literal, you must append the L or l suffix. Omitting the suffix causes the compiler to truncate the literal to double precision before assigning it to the long double variable.
// Correct: The 'L' suffix ensures the literal is treated as long double
long double precise_val = 3.14159265358979323846264338327950288L;

// Incorrect: Literal is truncated to double precision before assignment
long double truncated_val = 3.14159265358979323846264338327950288;

Formatted Input/Output

When interfacing with standard I/O functions (printf, scanf), long double requires the L length modifier combined with a floating-point conversion specifier (f, e, g, a).
#include <stdio.h>

int main(void) {
    long double num;
    
    // Input requires %Lf
    scanf("%Lf", &num);
    
    // Output requires %Lf (or %Le, %Lg). 
    // .19 specifies 19 decimal places of precision.
    printf("%.19Lf\n", num);
    
    return 0;
}

Standard Library Integration

The C standard library provides dedicated functions and macros for long double operations to prevent implicit downcasting to double. Math Functions (<math.h>) Functions operating on long double are suffixed with l.
#include <math.h>

long double base = 2.0L;
long double result = sqrtl(base); // Instead of sqrt()
long double power = powl(base, 3.5L); // Instead of pow()
Limits and Characteristics (<float.h>) The <float.h> header defines macros specific to long double (prefixed with LDBL_) that expose the implementation details of the type on the current architecture:
  • LDBL_MANT_DIG: Number of base-radix digits in the floating-point significand.
  • LDBL_DIG: Number of decimal digits that can be rounded and recovered without change.
  • LDBL_MIN / LDBL_MAX: Minimum normalized positive value and maximum representable finite value.
  • LDBL_EPSILON: The difference between 1.0 and the next representable long double value.
Master C with Deep Grasping Methodology!Learn More