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
2 answers
Constructing `long double` rvalue
Let's say I have the following C++ code:
#include
long double fn_d() {
return pow( double(4), double(3) );
}
long double fn_ld() {
return powl( long double(4), long double(3) );
}
MSVC is happy with this, but both GCC and Clang get…

geometrian
- 14,775
- 10
- 56
- 132
1
vote
1 answer
Negative output for long double
Why is the following code giving answer as -2.000000 for every input?
#include
#include
int main()
{
long long int s1,s2;
long double l,y,m=sqrt(2);
scanf("%Lf %lld %lld",&l,&s1,&s2);
y=l*m;
…

tarun Gupta
- 11
- 1
- 2
1
vote
1 answer
Long Double in Swift
In C, there is a type called long double, which on my machine is 16-bytes (128-bit). Is there any way to store a long double in Swift? I've tried type aliases (typedefs) of long double from an Objective-C header, but it doesn't show up in Swift. And…

SpilledMango
- 575
- 7
- 25
1
vote
1 answer
Substitutions for Eigen::MatrixXd typedefs
What is the simplest way to replace all Eigen::MatrixXds and Eigen::VectorXds with Vectors and Matrices that have long double elements?
Every basic floating point variable in my code is of type long double. Also, everytime I use a matrix or vector,…

Taylor
- 1,797
- 4
- 26
- 51
1
vote
0 answers
MongoDB cast double to long
I'm trying to convert the number 1477958757748.9697 to long in the mongo-shell. The NumberLong function throws an error:
> NumberLong(1477958757748.9697);
2017-06-03T08:52:56.306-0400 E QUERY [thread1] Error: number
passed to NumberLong must be…

neoexpert
- 465
- 1
- 10
- 20
1
vote
0 answers
long doubles displayed incorrectly in Code::Blocks
Why aren't long double numbers not displayed properly?
I'm using MinGw32 4.9.2. For example when a = 56 and b = 3, a is displayed as -2.6815615859885194e+154, b as -3 and the resulting operation is -5.075883675e-116
#include
#include…

Grzegorz
- 11
- 2
1
vote
2 answers
How to identify the precision of long double datatype
My compiler is telling me that the size of sizeof(long double) is 16 byte, which means it can represent a number up 2^128. Now, I want to know until how many digits the precision can handle. For instance, if x= 0.1234567812345678, can long double…

Medo
- 952
- 3
- 11
- 22
1
vote
1 answer
Long double overflows but value smaller than maximum representable value
I'm trying to compute a series using C++.
The series is:
(for those wondering)
My code is the following:
#include
#include
#include // exp
#include //setprecision, setw
#include //numeric_limits…

Devolution
- 31
- 6
1
vote
1 answer
C++ fabs(long double) compiler warning
I want to have the absolute value of a long double.
According to or , the following is available:
double fabs (double x);
float fabs (float x);
long double fabs (long double x);
However, when doing long double ld =…

Stingery
- 432
- 4
- 16
1
vote
0 answers
If I have two programs that produce the same out using doubles can I assume both programs are identical?
I'm writing a C++ program and in an attempt to fix a bug I've isolated a section of my main program into a separate file. I'll call the main program Prog1 and the separated section Prog2.
I've managed to successfully find and fix the bug in Prog2…

Paul Warnick
- 903
- 2
- 13
- 26
1
vote
1 answer
How to print binary representation of a long double as in computer memory?
I have to print the binary representation of a long double number for some reasons. I want to see the exact format as it remains in the computer memory.
I went through the following questions where taking a union was the the solution. For float,…

Enamul Hassan
- 5,266
- 23
- 39
- 56
1
vote
3 answers
Parse Long and Double
I just have a few lines of code C++ bellow:
long re = 103491683;
double temp = (double)re * (double)re;
cout<<"\n"<<"double * double = \t"<<(long)temp;
long temp2 = re * re;
cout<<"\n"<<"long * long = \t\t"<

duongtd23
- 101
- 1
- 6
1
vote
1 answer
When long-double calculator loses its precision?
My task was to write a code for a calculator that operates on long double. It turns out that after the certain point the calculator loses precision. For example it computes correctly 9999999 ^ 2, but as far as 99999999 ^ 2 it yields the result,…

SkogensKonung
- 601
- 1
- 9
- 22
1
vote
3 answers
Using long double
The following is my C++ program. I want to store a long number such as pi on a variable so I am trying to use long double. But when I run the program it only displays 3.14159 . How to store the full floating point number to the variable?
#include…
user5063431
1
vote
2 answers
Converting long double to CString
I am working on C++ MFC project build in unicode settings and I usually use function _ttof to convert CString to double but i couldn't find a function for long double which use TCHAR.
Thanks in advance.

AlaaL
- 333
- 9
- 28