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
7
votes
4 answers
x86-64 long double precision
What is the actual precision of long double on Intel 64-bit platforms?
is it 80 bits padded to 128 or actual 128 bit?
if former, besides going gmp, is there another option to achieve true 128 precision?

Anycorn
- 50,217
- 42
- 167
- 261
7
votes
6 answers
How can you easily calculate the square root of an unsigned long long in C?
I was looking at another question (here) where someone was looking for a way to get the square root of a 64 bit integer in x86 assembly.
This turns out to be very simple. The solution is to convert to a floating point number, calculate the sqrt and…

Philip Couling
- 13,581
- 5
- 53
- 85
7
votes
3 answers
Performance implications of long double. Why does C choose 64-bits instead of the hardware's 80-bit for its default?
For specifics I am talking about x87 PC architecture and the C compiler.
I am writing my own interpreter and the reasoning behind the double datatype confuses me. Especially where efficiency is concerned. Could someone explain WHY C has decided on a…

unixman83
- 9,421
- 10
- 68
- 102
6
votes
2 answers
Is long double in C++ an implementation of IEEE's binary128?
From https://en.wikipedia.org/wiki/Long_double:
In C++, long double refers to a floating-point data type that is often more precise than double-precision. However, as with C++'s other floating-point types, it may not necessarily map to an IEEE…

Eduardo
- 697
- 8
- 26
6
votes
0 answers
Valgrind leading to numeric issues with long doubles
I have the following function in my code that checks numbers for having allowed values (in log space):
template
static void check_if_normal(T t)
{
T additive_neutral_element = make_additive_neutral_element();
// probability is…

lo tolmencre
- 3,804
- 3
- 30
- 60
6
votes
1 answer
can't print correctly a long double in C
I am trying print a simple long double, but it doesn't work
What I tried:
long double ld=5.32;
printf("ld with le = %Le \n",ld);
printf("ld with lf = %Lf \n",ld);
printf("ld with lg = %Lg \n",ld);
Output:
ld with le = -3.209071e-105
ld with lf =…

Don
- 292
- 2
- 12
6
votes
1 answer
How do I use the numpy longdouble dtype?
I am trying to work with the np.longdouble dtype in my Python code, and am trying to use NumPy to manipulate long doubles that I get from a C module compiled with Cython.
Suppose I do this:
import numpy as np
print np.finfo(np.longdouble)
Machine…

Abhinav
- 268
- 1
- 7
- 19
6
votes
5 answers
Long Double in C
I've been reading the C Primer Plus book and got to this example
#include
int main(void)
{
float aboat = 32000.0;
double abet = 2.14e9;
long double dip = 5.32e-5;
printf("%f can be written %e\n", aboat, aboat);
…

reubensammut
- 182
- 1
- 1
- 12
5
votes
1 answer
Mixing NumPy longdouble and SymPy numerical evaluation – what about precision?
I have a code where one part of calculations is done using NumPy functions and longdoubles and the other using SymPy symbolic differentiation and numerical evaluation, then joined together (to SymPy float). Sympy evaluation can be done with…

arkhebuz
- 53
- 4
4
votes
1 answer
Output precision is higher than double precision
I am printing some data from a C++ program to be processed/visualized by ParaView, but I am having a problem with floating point numbers. Paraview supports both Float32 and Float64 data types. Float64 is equivalent to double with the typical limits …

iluvatar
- 872
- 10
- 21
4
votes
4 answers
Which function should be use to converting string to long double?
Note that in general, double is different from long double.
strtod converts string to double, but which function should be use to converting string to long double?

Amir Saniyan
- 13,014
- 20
- 92
- 137
4
votes
0 answers
Clang compiler (x86): 80 bit long double
I'm trying to use native 80 bit long double on x86 Windows platform. The GCC option -mlong-double-80 doesn't seem to work with clang. I tried
clang -target i386-windows -mlong-double-80 -c -O3 "test.c"
But the compiler shows me the error:
clang:…

Listener
- 91
- 7
4
votes
0 answers
128bit long doubles in ruby?
In my ruby code, I'm talking to a server that responds with 128bit long doubles ("128 bit long doubles", "binary128" or "quadruple precision floating points") as strings in binary format.
Is there a way to unpack these strings for use in ruby?…

Anthony Liekens
- 1,061
- 11
- 25
4
votes
2 answers
C++ very small floating point number, preciscion
I am dealing with a code which uses very small numbers of order 10^-15 to 10^-25. I tried using double and long double but i get a wrong answer as either 0.000000000000000000001 is rounded off to 0 or a number like 0.00000000000000002 is represented…

Md_Asher
- 69
- 2
- 3
4
votes
3 answers
Does Java's BigDecimal leverage the hardware architecture like long double in C++?
As I understand it, long double in C++ actually leverages the hardware architecture (at least for some architectures). Does BigDecimal in Java do this for small enough inputs?

Daishisan
- 290
- 1
- 6