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
0
votes
1 answer
Trying to print LDBL_MAX
I use CodeBlocks 20.03 with the embedded MinGW-W64 gcc compiler version 8.1.0 for Windows 10.
I am trying to print the LDBL_MIN and LDBL_MAX constants, normally in the range of 10e4932 but I get values in the range of 10e-317.
Here is my…

Xander Hr
- 1
- 1
0
votes
2 answers
Why is `isnan` returning 0 for a long double set to NAN?
#include
#include
int main()
{
long double x = NAN;
printf("x = %Lg\nisnan(x) = %d\n", x, isnan(x));
return 0;
}
When I run the above program, I get the output:
x = nan
isnan(x) = 0
According to the manpage, isnan…

flarn2006
- 1,787
- 15
- 37
0
votes
0 answers
Get the index of the closest value in a vector, with very small values in C++
I'm tryng to write a function that, given a sorted ascending vector vec and given a value value_vec[i], it gives me back the position of the element of the vector which is closer to the value.
std::vector vec { 0.0001, 0.0004, 0.004,…

fslack
- 189
- 9
0
votes
1 answer
Why do i get nan after swapping bits in long double value?
I had to write a program for my class that swaps 2 sets of bits in binary representation of some long double value. I know that in IEEE-754 standard nan appears when whole exponent is filled with ones. But in my case it is not fully filled, so i…

Timur Khr
- 15
- 5
0
votes
1 answer
Applying "not" operator on long double in C
I have below C code in which I have applied a not operator on a long double variable:
#include
int main()
{
long double a;
signed char b;
int arr[sizeof(!a+b)];
printf("\n%d",sizeof(arr));
return 0;
}
This code outputs…

Vipul Tyagi
- 547
- 3
- 11
- 29
0
votes
2 answers
can't figure out the sizeof(long double) in C is 16 bytes or 10 bytes
Although there are some answers are on this websites, I still can't figure out the meaning of sizeof(long double). Why is the output of printing var3 is 3.141592653589793115998?
When I try to execute codes from another person, it runs different from…

Matt Matt
- 11
- 1
0
votes
1 answer
Why double, long double are always showing 0 as output?
I am writing code to find the distance of a point(25,40000) from a fixed point(47,132000). The distance always printed to be 0.0000.
I have tried checking other combinations, giving smaller values of points, and printing them with %d, it works…

Apoorva Jain
- 11
- 5
0
votes
0 answers
_Generic macros of math functions in C - Windows 10/"long double" type bug
The problem at hand arises from the execution of the following code which constitutes example 16.15 (Chapter 16: The Preprocessor and the C Library) in Stephen Prata's book "C Primer Plus" (6th Edition). In what follows, I undertook the utmost care…

Urovoros Ofis
- 9
- 4
0
votes
0 answers
Why does std::atomic block indefinitely in C++14?
I am trying to adapt my program to use long double instead of double, in which I also use atomic numbers.
After the change I encountered something that looks like an infinite cycle in the std::atomic library.
Here is a sample code to illustrate the…

Dávid Tóth
- 2,788
- 1
- 21
- 46
0
votes
2 answers
What's bigger than a long double?
So I'm trying to find the result of 1.25 ÷ (2 ✕ 10^-12).
I first tried doing it with python, but the result was too big it returned a negative number.
So I tried doing it in C, using a long double, but it's still not enough.
PS. I'm using GCC v9.2.1…

VirtualCode
- 11
- 2
0
votes
1 answer
How to get the mantissa of an 80-bit long double as an int on x86-64
frexpl won't work because it keeps the mantissa as part of a long double. Can I use type punning, or would that be dangerous? Is there another way?

meisel
- 2,151
- 2
- 21
- 38
0
votes
0 answers
Program that is supposed to print the value of n! (n entered by the user) behaves strangely with long doubles in C
I'm currently testing the maximum values of n! where n is a positive integer entered by the user. I tested this with:
short
int
long
long long
float
double
With all of the above types the program prints the correct value. However, when I declare…

Shuster
- 167
- 5
0
votes
0 answers
printing long double goes wrong
I was working with Dev-Cpp with my TDM-GCC 4.9.2 64-bit Release. But suddenly got stuck in printing long double values.
#include
void main(){
long double a = 22.0/7.0;
printf("%Lf",a);
}
It compiled well. Then when I…

Kabir Uddin
- 1
- 2
0
votes
3 answers
Can i use long double to compute integers in c language
I try to write a factorial function to compute a large number(factorial(105)),its result have 168 digit, so use long double, but it seems to be a error, can't it use like this?
#include
long double factorial(long double n,long double base…

archi
- 19
- 2
0
votes
1 answer
Giving input 22222222222222222 for double but the output is 22222222222222224.000000 Why?
#include
int main()
{
printf("Enter the number:");
double num;
scanf("%lf",&num);
printf("%lf\n",num);
}
Input:22222222222222222
Output:22222222222222224.000000
Why it is giving output not like given.

kingmohan45
- 5
- 2