I've been googling for hours and still can't find the exact results of "what is the range of long double in c++". some say long double
is the same as double
. but sizeof double is 8 bytes and sizeof long double is 16 bytes. note that I'm using gcc.
Asked
Active
Viewed 705 times
3

Evg
- 25,259
- 5
- 41
- 83

user135142
- 135
- 9
-
1) https://en.cppreference.com/w/cpp/language/types 2) One can just simply print out `std::numeric_limits
::max()`, and `std::numeric_limits – Algirdas Preidžius Aug 10 '21 at 08:33::min()` to figure out the range on your system. -
2it depends: https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html – Alan Birtles Aug 10 '21 at 08:34
-
https://en.wikipedia.org/wiki/Extended_precision – Evg Aug 10 '21 at 08:35
-
2You can't find a definitive answer because most such ranges are implementation-dependent. – molbdnilo Aug 10 '21 at 08:43
-
in my case, i'm asking 128-bit floating point integers @molbdnilo . – user135142 Aug 10 '21 at 09:17
-
Please note that some of those 16 bytes may be just padding. – Bob__ Aug 10 '21 at 09:20
-
1note that even if `sizeof(long double)` is 16 bytes, it doesn't mean that all the bits are significant. Some may just be padding. Duplicates: [What is the size of float and double in C and C++?](https://stackoverflow.com/q/25524355/995714), [What is the range of the long double C++](https://stackoverflow.com/q/15320756/995714), [long double vs double](https://stackoverflow.com/q/3454576/995714), [Difference between long double and double in C and C++ (duplicate)](https://stackoverflow.com/q/14221612/995714) – phuclv Aug 10 '21 at 09:21
-
Does this answer your question? [What is the size of float and double in C and C++?](https://stackoverflow.com/questions/25524355/what-is-the-size-of-float-and-double-in-c-and-c) – phuclv Aug 10 '21 at 09:21
1 Answers
4
Why not ask your compiler? std::numeric_limits<long double>
is defined.
long double smallest = std::numeric_limits<long double>::min();
long double largest = std::numeric_limits<long double>::max();
long double lowest = std::numeric_limits<long double>::lowest();
std::cout << "lowest " << lowest << std::endl;
std::cout << "largest " << largest << std::endl;
std::cout << "smallest " << smallest << std::endl;
Running this code on godbolt.org with x86-64 GCC 11.2 gives me:
lowest -1.18973e+4932
largest 1.18973e+4932
smallest 3.3621e-4932
It might vary for your platform, of course.

Botje
- 26,269
- 3
- 31
- 41
-
1
-
3You'd need `lowest` to see the largest negative number in magnitude and thus the full "range". – rubenvb Aug 10 '21 at 08:38
-
Please note that those results are compatible with a [double extended precision](https://en.wikipedia.org/wiki/Extended_precision) 80-bit format. – Bob__ Aug 10 '21 at 09:26