`double` — C++ Keyword

`double` — C++ Keyword

The double keyword in C++: a double-precision IEEE 754 floating-point type.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

double

A double-precision floating-point type. On all modern platforms this is a 64-bit IEEE 754 binary64 value, providing approximately 15–16 significant decimal digits.

Syntax

double d;
double d = 3.14159265358979;
long double ld;   // at least as wide as double; often 80-bit extended on x86

Example

#include <print>
#include <cmath>
#include <cfloat>
#include <numbers>

int main() {
    double pi = std::numbers::pi;
    double r  = 5.0;

    std::println("{:.10f}", pi * r * r);   // 78.5398163397

    std::println("DBL_MAX: {:.2e}", DBL_MAX);       // ~1.80e+308
    std::println("DBL_EPSILON: {}", DBL_EPSILON);   // 2.22...e-16

    // std::sqrt returns double
    std::println("{}", std::sqrt(2.0));    // 1.41421356...
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}