long double Type

This page was translated by a robot.

The type long doublestores a real number , which is encoded as a floating point number with nowadays usually 80, 96 or 128 bits. A long doublecan represent the value range of 3.362103e-4932up 1.189731e+4932to 18 decimal places, both positive and negative.

Details

Depending on the system, processor, or compiler, the type requires long double10, 12, or 16 bytes to store the value. However, most implementations only use 80 bits to encode the floating point number. Depending on the system or processor, this type can be defined differently. This is a so-called extended floating point type according to the IEEE 754 standard.

The type long doublesometimes obeys strange laws, which were mainly set by the processor designers. For this reason, no detailed treatment is given on this page. However, if you are interested in the definition valid on your machine, you will find some macros in the floatslibrary that specify the value range of floating-point types more precisely. The following program supplies the values ​​for the type long doubleon the author's system:





3.362103e-4932
1.189731e+4932
64
18
-16381
-4931
16384
4932
1.084202e-19
#include <stdio.h>
#include <float.h>

int main(){
  printf("%Le\n", LDBL_MIN);         // smallest value
  printf("%Le\n", LDBL_MAX);         // biggest value
  printf("%i\n",  LDBL_MANT_DIG);    // radix digits of mantissa
  printf("%i\n",  LDBL_DIG);         // accurate decimal digits
  printf("%i\n",  LDBL_MIN_EXP);     // minimal radix exponent
  printf("%i\n",  LDBL_MIN_10_EXP);  // minimal decimal exponent
  printf("%i\n",  LDBL_MAX_EXP);     // maximal radix exponent
  printf("%i\n",  LDBL_MAX_10_EXP);  // maximal decimal exponent
  printf("%Le\n", LDBL_EPSILON);     // machine epsilon
  return 0;
}

Note that the mantissa number in the floats library usually adds an implicit bit. For more detailed information about what this bit is all about, refer to floating point coding .

When specifying fixed values ​​in the source code, long doublevalues ​​can be appended with a small l(ell) or a large Las a suffix. Both suffixes mean the same thing, but due to the visual similarity of the lowercase l(ell) to the digit 1(one), the author's recommendation is to always use the uppercase version. Without a suffix, the compiler assumes it is a doublevalue .

float
double
long double
1.234f
1.234
1.234L

Arithmetic Conversion

In the case of assignments, initializations or casts to a long doubletype, the compiler may perform arithmetic conversions .

The long doubletype is the most powerful type in C and C++. Its precision is usually specified in such a way that all integer types as well as all floating point types can be converted exactly.

However, arithmetic conversions of floating-point values ​​should be avoided whenever possible, regardless of whether they are implicitly or explicitly cast. They are still very expensive even in modern processors. It should also be noted that in certain situations floating point values ​​are automatically doubleconverted into a (see Promotion ).