🌐
Cppreference
en.cppreference.com › w › cpp › concepts › floating_point.html
std::floating_point - cppreference.com
November 24, 2024 - The concept floating_point<T> is satisfied if and only if T is a floating-point type. ... #include <concepts> #include <iostream> #include <type_traits> constexpr std::floating_point auto x2(std::floating_point auto x) { return x + x; } constexpr std::integral auto x2(std::integral auto x) { return x << 1; } int main() { constexpr auto d = x2(1.1); static_assert(std::is_same_v<double const, decltype(d)>); std::cout << d << '\n'; constexpr auto f = x2(2.2f); static_assert(std::is_same_v<float const, decltype(f)>); std::cout << f << '\n'; constexpr auto i = x2(444); static_assert(std::is_same_v<int const, decltype(i)>); std::cout << i << '\n'; }
🌐
Cppreference
en.cppreference.com › w › cpp › types › floating-point.html
Fixed width floating-point types (since C++23) - cppreference.com
February 13, 2025 - Unlike the fixed width integer types, which may be aliases to standard integer types, the fixed width floating-point types must be aliases to extended floating-point types (not float / double / long double), therefore not drop-in replacements for standard floating-point types. ... #include <stdfloat> #if __STDCPP_FLOAT64_T__ != 1 #error "64-bit float type required" #endif int main() { std::float64_t f = 0.1f64; }
Discussions

c++ - std::cout with floating number - Stack Overflow
I'm using visual studio 2015 to print two floating numbers: double d1 = 1.5; double d2 = 123456.789; std::cout More on stackoverflow.com
🌐 stackoverflow.com
c++11 - Does the C++ standard specify anything on the representation of floating point numbers? - Stack Overflow
For types T for which std::is_floating_point ::value is true, does the C++ standard specify anything on the way that T should be implemented? For example, does T has even to follow a sign/ More on stackoverflow.com
🌐 stackoverflow.com
c++ - Floating point format for std::ostream - Stack Overflow
You have to tell scanf whether the arg is a float (%f) or a double (%lf). Get it wrong and your program goes kablooey. ... You may "fill" the empty places with whatever char you want. Like this: std::cout << std::fixed << std::setw(11) << std::setprecision(6) << std::setfill('0') << my_double; More on stackoverflow.com
🌐 stackoverflow.com
Float comparison
The "correct" comparison for floating points does not exist. It depends on what you're comparing and why. It also depends on the values of the numbers you're comparing, as std::numeric_limits::epsilon()will not provide a good epsilon for the majority of use-cases. As such, no library function because it'd be impossible to please everyone; at least without resorting to a function which is so generic and trivial it may as well not exist. More on reddit.com
🌐 r/cpp_questions
16
6
February 12, 2024
🌐
Cplusplus
cplusplus.com › reference › string › stof
std::stof - Convert string to float
Parses str interpreting its content as a floating-point number, which is returned as a value of type float. If idx is not a null pointer, the function also sets the value of idx to the position of the first character in str after the number. The function uses strtod (or wcstod) to perform the ...
🌐
Alorelang
alorelang.org › doc › std_float.html
Class std::Float
Instances of the Float class are floating-point numbers (floats). A float is an approximation of a real number, and can represent whole and fractional numbers, both small and large in magnitude.
🌐
Cppreference
en.cppreference.com › w › cpp › header › stdfloat.html
Standard library header <stdfloat> (C++23)
February 13, 2025 - The fixed width floating-point types must be aliases to extended floating-point types (not float / double / long double), therefore not drop-in replacements for standard floating-point types. namespace std { #if defined(__STDCPP_FLOAT16_T__) using float16_t = /* implementation-defined */; #endif #if defined(__STDCPP_FLOAT32_T__) using float32_t = /* implementation-defined */; #endif #if defined(__STDCPP_FLOAT64_T__) using float64_t = /* implementation-defined */; #endif #if defined(__STDCPP_FLOAT128_T__) using float128_t = /* implementation-defined */; #endif #if defined(__STDCPP_BFLOAT16_T__) using bfloat16_t = /* implementation-defined */; #endif }
🌐
Rust
doc.rust-lang.org › std › simd › trait.StdFloat.html
StdFloat in std::simd - Rust
Returns the floating point’s fractional value, with its integer part removed.
🌐
Learn C++
learncpp.com › cpp-tutorial › floating-point-numbers
4.8 — Floating point numbers – Learn C++
You can see if your floating point types are IEEE 754 compatible with the following code: #include <iostream> #include <limits> int main() { std::cout << std::boolalpha; // print bool as true or false rather than 1 or 0 std::cout << "float: " << std::numeric_limits<float>::is_iec559 << '\n'; std::cout << "double: " << std::numeric_limits<double>::is_iec559 << '\n'; std::cout << "long double: " << std::numeric_limits<long double>::is_iec559 << '\n'; }
🌐
Cplusplus
cplusplus.com › reference › type_traits › is_floating_point
std::is_floating_point
All fundamental floating types (along with their aliases) are considered floating point types by this class, no matter their const or volatile qualification.
Find elsewhere
🌐
Cplusplus
cplusplus.com › reference › ios › defaultfloat
std::defaultfloat
When floatfield is set to defaultfloat, floating-point values are written using the default notation: the representation uses as many meaningful digits as needed up to the stream's decimal precision (precision), counting both the digits before and after the decimal point (if any).
Top answer
1 of 4
44

From N3337:

[basic.fundamental/8]: There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

If you want to check if your implementation uses IEEE-754, you can use std::numeric_limits::is_iec559:

static_assert(std::numeric_limits<double>::is_iec559,
              "This code requires IEEE-754 doubles");

There are a number of other helper traits in this area, such as has_infinity, quiet_NaN and more.

2 of 4
13

The C standard has an "annex" (in C11 it's Annex F) which lays out what it means for an implementation of C to be compliant with IEC 60559, the successor standard to IEEE 754. An implementation that conforms to Annex F must have IEEE-representation floating point numbers. However, implementing this annex is optional; the core standard specifically avoids saying anything about the representation of floating point numbers.

I do not know whether there is an equivalent annex for C++. It doesn't appear in N3337, but that might just mean it's distributed separately. The existence of std::numeric_limits<floating-type>::is_iec559 indicates that the C++ committee at least thought about this, but perhaps not in as much detail as the C committee did. (It is and has always been a damned shame that the C++ standard is not expressed as a set of edits to the C standard.)

🌐
C++ Programming Language
cpp-lang.net › standard library › mathematical functions › float_t
std::float_t; std::double_t | C++ Programming Language
#include <float.h> #include <math.h> #include <stdio.h> int main(void) { printf("%d\n", FLT_EVAL_METHOD); printf("%zu %zu\n", sizeof(float),sizeof(float_t)); printf("%zu %zu\n", sizeof(double),sizeof(double_t)); return 0; } Possible Result · 0 4 4 8 8 · Description ·
🌐
Programiz
programiz.com › cpp-programming › string-float-conversion
C++ String to float/double and vice-versa
#include <iostream> #include <string> int main() { std::string str = "123.4567"; // convert string to float float num_float = std::stof(str); // convert string to double double num_double = std::stod(str); std:: cout<< "num_float = " << num_float << std::endl; std:: cout<< "num_double = " << num_double << std::endl; return 0; }
🌐
Cppreference
en.cppreference.com › w › cpp › types › is_floating_point.html
std::is_floating_point - cppreference.com
September 24, 2024 - Provides the member constant value which is equal to true, if T is the type float, double, long double, or any extended floating-point types (std::float16_t, std::float32_t, std::float64_t, std::float128_t, or std::bfloat16_t)(since C++23), including any cv-qualified variants.
🌐
Learn Modern C++
learnmoderncpp.com › 2025 › 05 › 01 › new-floating-point-types-in-c23
New floating-point types in C++23 – Learn Modern C++
May 1, 2025 - In common with the C language we have been used to having the float, double and long double types available since the first versions of C++. (Did you know that long double often uses 80 bits of precision, padded to 96 bits, on 32-bit platforms, but a full 128 bits on 64-bit platforms?) In this article we’re going to discuss the <stdfloat> header new in C++23, which provides types with explicit precisions between 16 and 128 bits regardless of hardware platform, within the std:: namespace.
🌐
cpprefjp
cpprefjp.github.io › reference › stdfloat › float32_t.html
std float32_t
この型が定義される環境はISO/IEC/IEEE 60559 (IEEE 754) 準拠であるため、同じ変換順位をもつ浮動小数点数型 (floatとstd::float32_tのような) は同じ内部表現をもつ · #include <iostream> #include <stdfloat> #include <cmath> int main() { std::float16_t a = 1.0f16; auto b = 2.0f32; // bの型はstd::float32_t // aはより大きい精度の型float32_tに変換される auto c = a + b; // cの型はstd::float32_t // 精度を落とす縮小変換は明示的型変換で行う。 // 拡張浮動小数点数型は数学関数にも渡すことができ、
🌐
Stack Overflow
stackoverflow.com › questions › 4114284 › stdfloat-h-version-of-stdint-h
c - stdfloat.h version of stdint.h - Stack Overflow
Anything except very obscure and ... ancient mainframes or perhaps a small number of obscure non-conformant DSPs, float is 32 bits and double is 64 bits, in the standard formats....
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › stdstof-in-cpp
std::stof in C++ - GeeksforGeeks
August 2, 2017 - float stof (const string& str, size_t* idx = 0); float stof (const wstring& str, size_t* idx = 0); Parameters : str : String object with the representation of a floating-point number. idx : Pointer to an object of type size_t, whose value is set by the function to position of the next character in str after the numerical value. This parameter can also be a null pointer, in which case it is not used. Return Value : On success, the function returns the converted floating-point number as a value of type float. Below is the C++ implementation of std::stof :