Float (C++)

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{FormatInfo | name = float (C++) | formattype = electronic | subcat = Data types | subcat2 = C++ data types | subcat3 = | subcat4 ...")
 
(released)
 
Line 16: Line 16:
 
| uniform type  =
 
| uniform type  =
 
| conforms to    =  
 
| conforms to    =  
| released      =
+
| released      = 1983
 
| image          =  
 
| image          =  
 
| caption        =  
 
| caption        =  

Latest revision as of 07:04, 13 May 2015

File Format
Name float (C++)
Ontology
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.

[edit] Literals

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.

[edit] Characteristics

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

[edit] Other C++ data types storing floating point numbers

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox