Home > Mobile >  Difference in the amount of decimal numbers between double and long double
Difference in the amount of decimal numbers between double and long double

Time:10-01

What’s the difference between the amount of decimal values in a double data type and a long double data type in c?

CodePudding user response:

C does not require a difference in the amount of significant decimal digits between double and long double. They may be the same.

To report the number of significant decimal digits a floating point type can at least faithfully encode, see xxx_DIG.

#include <float.h>

printf("long double %d\n", LDBL_DIG); // min: 10, Typically 15, 18 or 33
printf("double %d\n", DBL_DIG);       // min: 10, Often 15
printf("float %d\n", FLT_DIG);        // min:  6, Often 6

CodePudding user response:

double - 15 decimal places

long double - 19 decimal places (on systems where 80-bit format is used)

80-bit is the most common format, but is not available on all systems.

https://en.cppreference.com/w/c/language/arithmetic_types#Real_floating_types

https://www.tutorialspoint.com/cprogramming/c_data_types.htm

  • Related