Search code examples
c++gcclong-double

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.


Solution

  • 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.