Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Nov 29, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Floating Point Types

C++ defines three floating points datatypes: float, double and long double. Some existing implementations support only two (and in some cases only one) of these three. On such implementations, double and long double are interchangeable.

Your implementation documents the floating point datatypes it supports and their characteristics in the header file <float.h> or <cfloat>. According to the IEEE specification, type float occupies 32 bits (4 bytes) of which 24 represent the mantissa, 7 bits contain the exponent and 1 bit holds the sign. Type double occupies 64 bits (8 bytes) 53 of which are for the mantissa, 10 bits are for the exponent and one bit is for the sign. Type long double occupies 80 bits (10 bytes) of which 64 are for the mantissa, 16 bits are for the exponent and one bit is the sign bit.

long double can represent the largest values and provides the highest precision, namely 18 digits after the decimal point. double has a precision of 15 digits and float's precision is limited to six digits.
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date