7

What is the range of long double in C++?

Yoda
  • 17,363
  • 67
  • 204
  • 344

4 Answers4

14

#include <limits>

std::numeric_limits<long double>::min()
//...
std::numeric_limits<long double>::max()

The definition of long double is compiler & platform dependent, it is at least the same as a double, thus, it may take 8, 12 (usually also for 80bits) or even 16 bytes (float128/quadruple precision) and has a range according to its size.

Sam
  • 7,778
  • 1
  • 23
  • 49
8

Use std::numeric_limits to find out.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
4

It is system (and processor, and compiler, and ABI) dependent. Look into <limits.h> and <math.h> and <float.h> standard headers.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
2

According to MSDN - Data Type Ranges (C++) and the www.cplusplus.com, the long double is the same as double, takes 8 bytes of space and lies in the range [-1.7E+308, 1.7E+308].

There are also other sites, like this, which says that long double takes 12 - 16 bytes.

Thomas Wilde
  • 801
  • 7
  • 15
Shimon Rachlenko
  • 5,469
  • 40
  • 51