Zorrito
int main(){ mpf_set_default_prec(256); mpf_t pi; mpf_set(pi, 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628); cout << setprecision(256); cout << "GMP:" << pi << endl; return 0; }
S.
int main(){ mpf_set_default_prec(256); mpf_t pi; mpf_set(pi, 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628); cout << setprecision(256); cout << "GMP:" << pi << endl; return 0; }
Unless mpf_set is a macro (which seems not), 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628 will be treated as only double in c/c++
S.
You may need mpf_set_str
S.
Sorry I have no knowledge on GMP, but your code just doesn't make sense in c/c++
S.
Then, what would happed when passing a 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628 to mpf_t?
S.
imho, it would be rounded as double, lossing its precision, and then converted to mpf_t
S.
So to keep the precision, you need to convert a c-style string to mpf_t
Zorrito
You may need mpf_set_str
I tried this, and it's giving me the same kind of error.
S.
show the code and the full complaint from the compiler
Zorrito
show the code and the full complaint from the compiler
#include <iostream> #include <gmp.h> #include <iomanip> const int prec = 256; int main(){ float pif = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628; double pidf = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628; long double pildf = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628L; mpf_set_default_prec(prec); mpf_t pimpf; mpf_set(pimpf, 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628); cout << setprecision(prec); cout << "Float: " << pif << '\n'; cout << "Double: " << pidf << '\n'; cout << "Long: " << pildf << '\n'; cout << "GMP: " << pimpf << endl; return 0; }
S.
float pif = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628; double pidf = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628; long double pildf = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628L; they're plainly wrong here
S.
None of float, double, and long double, can store such a high precision
Zorrito
None of float, double, and long double, can store such a high precision
I know they can't. They're just test variables for me to check their precision against my mpf_t variable.
Zorrito
I know they can't. They're just test variables for me to check their precision against my mpf_t variable.
When I use mpf_set_d, I get the same precision as the double variable (as expected), but the compiler doesn't know what to do when I do mpf_set.
S.
You may have tried, const char* p = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628"; mpf_t f; ... mpf_set_str(f, p, 10);
S.
Isn't there any example snippet of GMP from the official documentation?
Anonymous
Nice bot
Zorrito
Isn't there any example snippet of GMP from the official documentation?
https://gmplib.org/manual/Assigning-Floats.html#Assigning-Floats
S.
That got rid of the error, but now, it's printing pi=4.
you may need gmp_printf and proper calling
S.
That got rid of the error, but now, it's printing pi=4.
By a simple search I found: mpf_t f; mpf_init2(f, 64); mpf_set_str(f, "0.0415373652931074065807663354", 10); gmp_printf ("fixed point mpf %Ff\n", f);
S.
Please test it
Zorrito
Using gmp_printf: For pi, I'm just getting 4.000000, and for the code you want me to test, I got 0.000000.
S.
what's your full code for test?
Zorrito
Oh, I had a typo. Your test code worked fine (printed 0.041537).
S.
mp_printf ("fixed point mpf %.64Ff\n", f);
S.
try again?
S.
by default it only outputs 6 digits
S.
( like printf
S.
Full precision?
Zorrito
Do you have a link to a reference?
S.
No. YOu may need to read the official manual
S.
Or some examples from github
Zorrito
Type long double gave me 3.141592653589793238(51280895940618620443274267017841339111328125) Type mpf_t gave me 3.1415926535897932384626433832795028841971693993751058209749445923 (all decimal places are correct)
S.
ur welcome
Zorrito
A big part of the problem was that I did not get to the part about the gmp_printf function, so I used what I knew lol. I still think it's weird that mpf_set doesn't work, but as long as I have this workaround, I guess it won't matter too much.
S.
because none of the default data types has such a high precision
Zorrito
because none of the default data types has such a high precision
Oh, I see :o When you put it that way, it makes a lot more sense.
Medina
anyone study networking or work as networking? message me please.
S.
anyone study networking or work as networking? message me please.
You can just post any c/c++ relevant questions here
Medina
okay. thanks 🙏🏼
Ибраги́м
https://github.com/dpilger26/NumCpp
MᏫᎻᎯᎷᎷᎬᎠ
Yeah What the fuck
Anonymous
hi
klimi
Hi
Mitesh
hi
Hi give your introduction
Mitesh
Why what
Just for know about him technical background in c
klimi
There are 5580 users ...
Mitesh
@CodeHeads is new
S.
Not really understanding what's going on
Anonymous
Me too
klimi
@CodeHeads is new
You're new too
Mitesh
And?
and i want to know about role of c in him technical field
Anonymous
and i want to know about role of c in him technical field
Sorry, am a Developer from Germany in programm in c#, Delphi, Python, PHP and now i want learn c++
Mitesh
You're new too
ya bro. i have introduced myself. when i was join Group members also call me to introduce
klimi
And to be honest.... We don't care at all if you introduce or not, there are so many people that it is not possible to remember everything
S.
Beautiful pfp btw
thx. love cats.
Anonymous
Ok i will do it
Bruce
What is EOF(end of function) and how it is used in c language
Bruce
My teacher tried to explain ,but I didn't understand