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 double keyword in C designates a double-precision floating-point data type used to represent fractional numbers. It is the default data type for floating-point literals in C and typically conforms to the IEEE 754 binary64 standard.

Technical Specifications

While the C standard does not strictly mandate the underlying representation, on virtually all modern architectures, double possesses the following characteristics:
  • Memory Size: 8 bytes (64 bits).
  • Bit Layout (IEEE 754):
    • 1 Sign bit
    • 11 Exponent bits
    • 52 Mantissa (significand) bits
  • Precision: 15 to 17 significant decimal digits.
  • Range: Approximately ±2.225×10308\pm 2.225 \times 10^{-308} to ±1.797×10308\pm 1.797 \times 10^{308}.
  • Standard Limits: Defined in the <float.h> header as DBL_MIN and DBL_MAX.

Syntax and Initialization

Floating-point literals without a suffix are treated as double by the compiler. They can be written in standard decimal notation or scientific (exponential) notation.
double uninitialized_var;
double standard_notation = 3.141592653589793;
double scientific_notation = 6.022e23; // 6.022 * 10^23
double negative_exponent = 1.6e-19;    // 1.6 * 10^-19

Format Specifiers

Input and output operations via the standard I/O library (<stdio.h>) require specific format specifiers. There is a critical distinction between reading and writing a double. Output (printf) When passed to variadic functions like printf, float arguments are automatically promoted to double. Therefore, the standard specifier for printing a double is %f (or %e for scientific notation, %g for the shortest representation).
double val = 123.456;
printf("%f\n", val);  // Standard decimal output
printf("%e\n", val);  // Scientific notation: 1.234560e+02
Input (scanf) When reading input, you must pass a pointer to the exact type. You must use the %lf (long float) specifier to read into a double variable. Using %f will result in undefined behavior, as scanf will attempt to write a 4-byte float into an 8-byte double memory space.
double input_val;
// %lf is strictly required for scanf
scanf("%lf", &input_val); 

Type Promotion and Literals

Because floating-point literals are double by default, assigning a literal to a standard float causes an implicit downcast, which may trigger compiler warnings regarding truncation.
// The literal 3.14 is an 8-byte double.
// It is implicitly truncated to a 4-byte float here.
float a = 3.14; 

// The 'f' suffix explicitly types the literal as a float.
float b = 3.14f; 

// The literal matches the variable type perfectly.
double c = 3.14; 
During arithmetic operations involving both float and double, the float operand is implicitly promoted to double before the operation is evaluated, yielding a double result.
Master C with Deep Grasping Methodology!Learn More