Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the exact range of long double in c++?

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.

like image 445
user135142 Avatar asked Jan 21 '26 17:01

user135142


1 Answers

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.

like image 129
Botje Avatar answered Jan 23 '26 08:01

Botje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!