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
3
votes
0 answers
Is it possible to check the "long double" type being used?
I'd like that an application would be able to know if it's running on a system whose "long double" type is a synonym for "double", or a true 128bit IEEE quad precision, or an 80bit Intel extended format, or a "double-double".
Is it possible to check…

cesss
- 852
- 1
- 6
- 15
3
votes
4 answers
Cout long double issue
So, I'm working on a C++ project. I have a var of long double type and assigned it a value like "1.02"
Then, I try to use cout to print it and the result is: -0
I already tried to use setprecision and all I found googling the problem.
What is the…

nervousDev
- 75
- 3
- 9
3
votes
1 answer
Difference between double and long double in c++
Can someone explain the differences between doubles and long doubles except for the difference in precision to me? I wrote a program to solve a gravitational n-body problem so i basically integrate second order differential equations and my program…

W. Verbeke
- 355
- 2
- 12
3
votes
3 answers
accessing long double bit representation
TLDR; Does the following code invoke undefined (or unspecified) behaviour ?
#include
#include
void printme(void *c, size_t n)
{
/* print n bytes in binary */
}
int main() {
long double value1 = 0;
long double value2 =…

andreabedini
- 1,295
- 1
- 13
- 20
3
votes
2 answers
Sum of two "np.longdouble"s yields big numerical error
Good morning,
I'm reading two numbers from a FITS file (representing the integer and floating point parts of a single number), converting them to long doubles (128 bit in my machine), and then summing them up.
The result is not as precise as I would…

matteo
- 289
- 2
- 11
2
votes
2 answers
Is long double useful in ANSI C?
There is a data type in C89 (ANSI C) standard called long double, but there is no any mathematical function to support long double (). For example, sin function accepts a long argument.
C99 supports mathematical functions for long double.
My…

Amir Saniyan
- 13,014
- 20
- 92
- 137
2
votes
1 answer
Long double output as 0.000000000000 in c lang
I am coding in Code::Blocks, in the C programming language:
#include
int main() {
float var1 = 3.145926535897932;
double var2 = 3.145926535897932;
long double var3 = 3.14159265389793213456;
printf("%d\n", sizeof(float));
…

Rhutuja Kakade
- 21
- 2
2
votes
1 answer
gcc 9.3.0 printf %Lf output not correct
printf("%Lf", long double) truncates the output to double. Or, am I doing something wrong?
Gcc 9.3.0 Ubuntu 20.04.2, Linux 5.8.0-59-generic
printf("print m_pi %.45f\n", M_PI);
printf("print m_pil %.45LF\n", M_PIl);
printf("maple Pi …

tomdean1939
- 39
- 2
2
votes
1 answer
Long double precision error saturation in RK integrator
I'm trying to write an integrator which uses long doubles for very high precision. I know that my system architecture has long double support, but for some reason, the precision of my integrator maxes out at 16 significant digits. Here's some code…

David
- 424
- 3
- 16
2
votes
1 answer
Format specifier %Lf is giving errors for `long double` variables
I am getting the following errors:
In function 'main':
[Warning] unknown conversion type character 'L' in format [-Wformat=]
[Warning] too many arguments for format [-Wformat-extra-args]
In function 'error_user':
[Warning] unknown conversion type…

Henry
- 697
- 1
- 6
- 16
2
votes
1 answer
Support for float128 (np.longdouble) in scipy.stats
I would like to make some probability computations with scipy.stats, and avoid under/overflows:
in addition to using the appropriate log-functions, I tried to increase the float precision using numpy.longdouble (float128 on Ubuntu).
However, the…

PlasmaBinturong
- 2,122
- 20
- 24
2
votes
3 answers
Precision of floating-point data types in C++
Why don't the precision of floating-point data types grow proportional to its size? E.g.:
std::cout << sizeof(float) << "\n"; // this gives 4 on my machine "debian 64 bit" with "gcc 6.3.0"
std::cout << std::numeric_limits::digits10 <<…

Bobo Feugo
- 162
- 1
- 10
2
votes
2 answers
Floating point inexact result with not-too-small decimal fraction - is there a way to overcome?
I have a piece of code that repetitively decreases a variable which starts at 1. After two iterations, the result is inexact, which came as a surprise.
The effective process can be shown by the following two lines:
>> (1 - 0.1) - 0.9
0
>> (1 - 0.05…

laugh salutes Monica C
- 131
- 4
2
votes
1 answer
Error with long doubles on PowerPC when compiling with gcc
I'm running into a curious bug when I assign values to long double variable types. (PowerPC architecture, gcc v4.9.2)
Specifically:
const constexpr long double DEGREE_TO_RAD = 0.0174532925199432954743716805978693;
const constexpr long double…

Fred Byrd
- 233
- 2
- 6
2
votes
2 answers
Implementing equations with very small numbers in C - Plank's Law generating blackbody
I have a problem that, after much head scratching, I think is to do with very small numbers in a long-double.
I am trying to implement Planck's law equation to generate a normalised blackbody curve at 1nm intervals between a given wavelength range…

chewdonkey
- 75
- 9