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
2 answers
How to convert a string into a long double?
To start off, I have thoroughly examined other questions on that matter and nothing helped me. I need to convert a string into a long double type, and nothing works for me.
string a="634.232";
long double x;
x=strtold(a.c_str(),0);
For example:…

YogoWafel
- 101
- 2
- 9
0
votes
1 answer
Binary files printing and desired precision
I'm printing a variable say z1 which is a 1-D array containing floating point numbers to a text file so that I can import into Matlab or GNUPlot for plotting. I've heard that binary files (.dat) are smaller than .txt files. The definition that I…

yCalleecharan
- 4,656
- 11
- 56
- 86
0
votes
1 answer
Return same double only if the double is an int? (no decimals) Obj-C
I'm using a for-loop to determine whether the long double is an int. I have it set up that the for loop loops another long double that is between 2 and final^1/2. Final is a loop I have set up that is basically 2 to the power of 2-10 minus 1. I am…

Milo
- 5,041
- 7
- 33
- 59
0
votes
2 answers
C++ Builder 2009 Float vs Long Double
I'm looking at some legacy code, which tries to cast a long double into a float. From reading http://www.cplusplus.com/forum/beginner/34088/ it looks like the long double has a sizeof() of 16 where the float has a sizeof() of 8.
When the float…

James Oravec
- 19,579
- 27
- 94
- 160
0
votes
0 answers
NetBeans wrong output for acos(-1)
I had an assignment that dealt with calculating pi by a few different iterative methods and comparing it with the value calculated by pi = acos(static_cast(-1.0)) (storing as a long double). For some reason, NetBeans gives me…

spartanhooah
- 183
- 4
- 15
0
votes
1 answer
which compilers give longest long double
I may be doing something very stupid here, but i've reached the limit of what double can achieve and on my compiler (i'm using newest xcode on a mac) long double seems no better.
I've read elsewhere that the length of long double depends on the…

zephyr
- 215
- 2
- 13
0
votes
2 answers
Why is "long double" type of a variable producing absurd output while "float" and "double" type works fine?
All I want the following program to do is to print the product of all positive numbers less than 30 (in both exponential and non-exponential forms). It works fine when the variable product is declared as a float or a double,but produces totally…

Rüppell's Vulture
- 3,583
- 7
- 35
- 49
-1
votes
2 answers
Packing long double with int
On gcc/clang, long double use 10 bytes but take 16 bytes. It'd be good if this struct is 16 bytes but it's actually 32 bytes, wasting half of bandwidth.
struct {
long double x;
int id;
};
I tried to union two values, but since compiler…

l4m2
- 1,157
- 5
- 17
-1
votes
1 answer
converting doubles to long doubles, understanding of 'binary vs. decimal' ambiguity? and is there a standard solution?
[edit 2021-09-26]
sorry!, I have to admit that I asked crap here, explanation follows. I don't think I should post this as an 'answer', so as an edit:
I'm still curious how a 'double' value of 0.1 converts to a long double!
But the focus of the…

user1018684
- 9
- 4
-1
votes
1 answer
How do I print a long decimal number in c?
I need the program to print "0.03571428". Instead my program prints only 0.035714. Sorry for the stupid question but I am a beginner as you can see!
int main(int argc, char *argv[]) {
long double a;
int b = 1, c = 28;
a =…

Demetrio Loddo
- 23
- 2
-1
votes
1 answer
Why can't I prime factor numbers above a certain magnitude?
I'm trying to write a program in C++ that will prime factor numbers that have 12 digits. Here's my code:
#include
using namespace std;
int main()
{
long double userInput;
long double divisor = 2;
long double dividend;
cout <<…

David Bippes
- 65
- 2
- 4
-4
votes
3 answers
Inverting the exponent of a long double gives me an insane result
I am trying to invert the exponent of a long double.
Suppose x = 3.5e1356. I want x to be 3.5e-1356.
I have this code:
long double x = 3.5e1356L;
int exponent;
long double fraction = frexpl(x, &exponent);
// recreate number with an inverted…

Duck
- 34,902
- 47
- 248
- 470