float (C++)

From Just Solve the File Format Problem
Revision as of 07:04, 13 May 2015 by VolodyA! V Anarhist (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
File Format
Name float (C++)
Released 1983

C++ float is the smallest possible floating point data type available. Unlike many other languages C++ doesn't use float as the default floating point, see double for that.

It is not possible to enumerate float values, and thus it cannot be used in constructs like switch.


Literals that need to be differentiated from double must be followed by f or F.

float a = 1.5; // This is a double that gets converted into a float
float b = 1.5f; // This is a float that gets stored in a float

Besides that float can store positive infinity, negative infinity, and NaN (not a number). NaN is generated when the result is mathematically ambiguous or impossible to determine, for example 0÷0.


The <cfloat> library consists of the following constants describing the behaviour of float

  • FLT_RADIX — base of the floating point numbers.
  • FLT_MANT_DIG — number of mantissa digits.
  • FLT_DIG — number of significant digits that can be stored.
  • FLT_MIN_EXP — minimum negative exponent.
  • FLT_MAX_EXP — maximum positive exponent.
  • FLT_MIN_10_EXP — minimum base-10 negative exponent that can be transformed into a valid float
  • FLT_MAX_10_EXP — maximum base-10 positive exponent that can be transformed into a valid float
  • FLT_EPSILON — the difference from 1.0f to the smallest possible value that is greater than 1.0f
  • FLT_MIN — the smallest possible value that is greater than 0.0f

Other C++ data types storing floating point numbers

Personal tools