7

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

Yoda
  • 16,053
  • 60
  • 184
  • 315
  • 1
    @H2CO3: That's specific to Visual Studio. – Benjamin Lindley Mar 10 '13 at 09:32
  • @BenjaminLindley Yeah, and I rarely link to MS-specific resources, but I wanted to illustrate how easy it would have been to find the information OP was looking for. –  Mar 10 '13 at 09:32

4 Answers4

13

#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,688
  • 1
  • 21
  • 47
8

Use std::numeric_limits to find out.

Some programmer dude
  • 380,411
  • 33
  • 383
  • 585
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
  • 216,767
  • 17
  • 275
  • 509
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
  • 671
  • 5
  • 15
Shimon Rachlenko
  • 5,419
  • 41
  • 50