Questions related to `long double` floating-point data-type (numbers) as commonly found in languages like C and C++. Sometimes referred to as quadruple-precision floating-point data-type (numbers).
Questions tagged [long-double]
162 questions
1
vote
1 answer
changing from double to long double in c++ no more gives correct results
In order to increase the accuracy, I have been trying to upgrade a program from double to long double. However, I got the following error.
haread.cpp:178:43: error: no match for ‘operator*’ in ‘2.0e+0 *
std::operator+ [with _Tp = long…

Population Xplosive
- 581
- 2
- 8
- 18
1
vote
1 answer
Actual long double precision does not agree with std::numeric_limits
Working on Mac OS X 10.6.2, Intel, with i686-apple-darwin10-g++-4.2.1, and compiling with the -arch x86_64 flag, I just noticed that while...
std::numeric_limits::max_exponent10 = 4932
...as is expected, when a long double is actually…

dmb
- 603
- 4
- 11
1
vote
2 answers
Visual C++ x86 ABI: how does VC++ return value?
I know 1/2/4-byte integers are returned in eax, and 8-byte integers are returned in eax:edx.
By the way, how are 4/8/16-byte floating-point values (Maybe I remember long double might be 16 bytes..) returned in cdecl/stdcall?
Thanks to…

ikh
- 10,119
- 1
- 31
- 70
1
vote
2 answers
Want to calculate 18 digits but will only calculate to 6? Using long double but still won't work
I've written a program to estimate pi using the Gregory Leibniz formula, however, it will not calculate to 18 decimal points. It will only calculate up to 5 decimal points. Any suggestions?

Tyler
- 1,933
- 5
- 18
- 23
1
vote
4 answers
Weighted probability with long doubles
I am working with an array of roughly 2000 elements in C++.
Each element represents the probability of that element being selected randomly.
I then have convert this array into a cumulative array, with the intention of using this to work out which…

user1890050
- 71
- 6
1
vote
1 answer
Why is this long double not printing out correctly using printf?
I need to do division using long double, on the order of 1/10^23, however the numbers get cut off when i check them using printf. Does anyone one know how I can see the full number? For example:
long double a = 1;
long double b = 3;
printf ("%Lf",…

mihajlv
- 2,275
- 4
- 36
- 59
0
votes
3 answers
Double precision: Multiplication of big numbers
I have some simple operations (subtraction, multiplication) with big numbers (integers). They are so big, that I have to store them into long double variable. That is fine, but for some cases multiplication looses precision.
Example:
A =…

Gaim
- 6,734
- 4
- 38
- 58
0
votes
3 answers
How can you set data type of #define to long double?
I have a c-code where I define some variables for pre-processing using the #define command.
However, I think that there are ways to toggle between float and double data types by doing for example:
#define 1.0f // float data type
or
#define 1.0 …

Abhinav Kumar
- 1,613
- 5
- 20
- 33
0
votes
0 answers
gcc13: long double has almost the same precision of libquadmath; are they both 80-bit float implementations?
I thought GCC would currently (2023) implement 80-bit floats for long-double, and 128-bit floats with libquadmath...
However, with gcc 13.2.0 on an amd64 architecture (AMD FX-8320E), I see that the limits for long double and __float128 seem quite…

johjs
- 81
- 3
0
votes
1 answer
Split up long C++ double literal into multiple lines
I'm implementing log_10(x) in terms of log_2(x) with the following formula
log_10(x) = log_2(x)/log_2(10).
I want to make this function generic (eg I would like it to work with could work with Boost's cpp_bin_float_quad) and, as far as I know,…

Shawn McAdam
- 51
- 8
0
votes
2 answers
Conversion between `long double` and `std::uintmax_t` loses precision on whole numbers
I've made a class that allows to split long double to an integer value and a binary exponent (for some precise calculations).
My problem is pretty hard to reproduce because the class usually works great but on one specific machine I've tested it on,…

Piotr Siupa
- 3,929
- 2
- 29
- 65
0
votes
0 answers
What is stored in bits of long double variable?
I printed such a code to see max value of 128 bits long double variable:
long double num = numeric_limits::max();
printf("%Lf", num);
and got output of more than 4 thousands digits which is can not be stored in 128 bits.
Then what is…

Max Popov
- 357
- 2
- 12
0
votes
0 answers
(C++) SQRT function only outputs four decimal places
I'm trying to find the square root of a number through this function and it's not very precise. For example, if you enter 496, my output is 22.2711, while my professor's sample output is 22.271057.
I've tried making an int, double, and long double…

Sunny
- 1
- 1
0
votes
1 answer
Why is double 0.1 more accurate than its long double version?
How can I understand this another floating-point paradox --- 0.1 represented as double is more accurate than 0.1 represented as long double?
In [134]: np.double(0.1)
Out[134]: 0.1
In [135]: np.longdouble(0.1)
Out[135]: 0.10000000000000000555

zell
- 9,830
- 10
- 62
- 115
0
votes
1 answer
long double input to scanf
I am using windows 10 and MinGW-x64 gcc 8.1.0. I was trying to take a long double as input using scanf. Here is the code:
#include
#include
int main(int argc, char const *argv[])
{
long double a;
scanf("%Lf",&a);
…

tachyon
- 43
- 1
- 7