Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

long double — standard floating-point type

`long double` is a distinct standard floating-point type with at least the precision of `double`. It guarantees neither extra precision nor a particular size. The `L` suffix creates literals of this type.

Version: C++23; repository compiler flag, production runtime not attested

Syntax

long double name = 1.0L;

long double is a standard floating-point type distinct from float and double. It provides at least the precision of double and includes all its values. However, do not assume that it offers additional precision digits or occupies a particular number of bytes.

A declaration takes the form long double name = 1.0L;. The suffix L or l gives a floating-point literal the type long double; without a suffix, such a literal has type double. Writing long double name = 0.1; first creates a double value, so the later conversion cannot recover lost precision. Use 0.1L to give the literal the intended type from the start.

Higher precision does not mean exact arithmetic for arbitrary decimal fractions. Representation and operation accuracy depend on the implementation. Inspect the target implementation through std::numeric_limits<long double> from <limits>: digits describes precision in base radix, while max_digits10 gives the number of decimal digits sufficient to distinguish different values.

The example divides small, exactly representable integers written as long double literals; the expected result is 3. This entry targets C++23, whereas the supplied source is an evolving working draft, not a frozen C++23 publication.

Examples

#include <iostream>

int main() {
    long double distance = 6.0L;
    long double time = 2.0L;
    long double speed = distance / time;
    std::cout << speed << '\n';
}

Result

3

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources