Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the range of the long double C++ [duplicate]

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

like image 332
Yoda Avatar asked Mar 10 '13 09:03

Yoda


People also ask

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

It is system (and processor, and compiler, and ABI) dependent. Look into <limits.h> and <math.h> and <float.h> standard headers. Show activity on this post. 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].

What is the difference between double and long double in C?

For example, in some compiler implementations, double and long double are the same size with the same range of values, while in other implementations, long double is wider and has a broader range of values than double. The standard does not define any unsigned floating-point data types.

What is the size of a long double?

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. Show activity on this post. Use std::numeric_limits to find out. Show activity on this post.

What is the use of sizeof data type in C?

Data types, and their size and range, play an important role in C programming. The sizeof () operator gives the number of bytes required to store a value in memory of a specific form. However, to prevent overflow and underflow errors in programming, we must be aware of a type's range.


1 Answers

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

like image 173
Sam Avatar answered Oct 03 '22 23:10

Sam