increase long double accuracy [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
how can I increase accuracy in double.
for example in this code:
#include <stdio.h>
int main() {
long double a = (long double) 5 / 3;
printf("%.62LLF", a);
return 0;
}

Floating Point Numbers have a limited precision. Mandatory Reading Here.
The boost.multiprecision library can give you access to higher precision floating point numbers, whether in the form of quad types which simply double the precision of double, or in the form of arbitrary precision rational numbers. If you're willing to take the time to learn how to install and use that library, you'll be able to improve the precision of your numbers.

Related

Floating point number answer difference between c++ and calculator [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am calculating a floating point number by formula: number=1/(n-2.001)
Where n is any integer from 1 to infinite.
But it give me different answer in laptop and scientific calculator.
C++ calculation : 0.333444
Calculator answer: 0.3334444815
I have to get all digits in c++. How i get this.
Decimal equivalent of 1/3 is 0.33333333333333….
An infinite length number would require infinite memory to store, and we typically have 4 or 8 bytes. Therefore, Floating point numbers store only a certain number of significant digits, and the rest are lost.
NOTE : When outputting floating point numbers, cout has a default precision of 6 and it truncates anything after that.
The precision of a floating point number defines how many significant digits it can represent without information loss.
Therefore in your case only 6 decimals points are outputted and rest are turncated
To change the Precision of floating-point data types in C++ check this

C++ full number of degree [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is a simple code that counts two to the right degree. Starting from somewhere around 60 degrees the answer is incorrect.
I need to count 2^200. The answer shouldn't be in the form like "1.606938e+60", but by numbers. How to do this in C++?
#include <iostream>
using namespace std;
int main()
{
unsigned long long int n,z;
cin>>n;
z=pow(2,n);
cout<<z<<endl;
return 0;
}
You need to use std::set_precision(n) to get it to print in the format that you're expecting it, but if your numbers get high enough, you'll run into a second issue. pow returns a double, which loses precision in a big way with huge numbers. For more information on how to solve that, refer to this Stack Overflow answer.
Anyway you cant print such big number as a single integer or double value in c++ (not yet). Maybe there exist some 256 or 512 machine architectures and implementations which build in types are large enough, but its not possible in common. You probably need to use some data structure to store you number and operate on that.
This, this and this examples may be helpful.

Division Console output with a comma not rounded [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Is there a way for the console output to be a decimal number with a comma my output is always rounded and i can barely us it like this.
Int a = 90 ;
Int b = 7;
Int c = a/b;
This out puts 13 not the actual value.
It is advice rewritten from my comment:
Please check any elementary C++ tutorial :) For your information there isn't bult-in type Int in C++, so it seems that you want to ask about int type division. The answer could be: store your result in some floating point type as float :)
You're welcome!
use float or double instead. int will never provide you with decimals.
Example:
float a=90,b=7;
float c = a/b;
printf("%.2lf",c);
The code avobe mentioned will write 2 decimals. If you want more, just change the 2 here %.2lf for your amount of decimals required.

Best way to store coords: struct of uints or double? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have geo coordinates in format N000.11.22.333 E444.55.66.777. Milliseconds are necessary for precision. I need to perform calculations like calculate coord given coord0, angle and distance. Sure I want to keep precision not less than milliseconds. This and other calculation algorithms often use trigonometric functions to get a result.
Which solution is better: 1) use struct that contains degrees, minutes, seconds and milliseconds as uints and overload operators for manipulate them; 2) use double type and convert coords to decimal view for calculations. As I think float type is not enough stable on these calculations.
Be used for qt 5.9 x64 project, msvc 2017, win platform only
Pick whichever is easiest (almost definitely a double). A double is more accurate than a ruler or a careful surveyor. Lots of navigation software uses a single 32-bit integer for lat and one for long.

How do I make a basic c++ calculator calculate decimals [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a decent grasp with c++, and I made a basic calculator that can add, subtract, multiply, and divide. but I am having a hard time trying to get it to calculate decimals. Help please???
Read http://floating-point-gui.de/ first.
You don't calculate decimals, you display a floating point number (often some double) with some decimals.
Use things like std::showpoint & std::fixed ...
If you want to show a lot of correct digits, you need to do arbitrary precision arithmetic or BigNums. Then use a library, such as GMPlib