On Wednesday, May 1, 2013 9:08:12 PM UTC+1, Vaibhav Tulsyan wrote:
> 1. Are you using 'mpz_class' as a generalisation of all classes of the gmp
> library? I'm asking because in the tutorial they've used mpz_t. Will that
> factorial code work if I use mpz_t as the return type instead of mpz_class?
>
There is a C API discussed in the tutorial
There is also a C++ environment defines three classes:
mpz_class for integers
mpq_class for rationals
mpf_class for big precision real numbers
in which most code written in the natural way will work.
> 2. Is usage of set() compulsory? Or can we use the normal way to initialize
> the variable with a value? For e.g., mpz_class x = 0;
Not compulsory. I was only trying to illustrate that you can replace ints with
mpz_classes, and almost everything just compiles and works as you might expect.
Here is some more ordinary code:
mpz_class x = 1000 * 1000; // one million
x *= x*x; // 10 **18
x *= x*x; // 10 **54
cout << x << endl;
mpq_class half(1,2); // define a rational half
cout << half << endl;
cout << half*x << endl; // multiply 10^54 by a half
mpf_class f = half*x; // express as a floating point
cout << f << endl;
gives this output:
1000000000000000000000000000000000000000000000000000000
1/2
500000000000000000000000000000000000000000000000000000
5e+53
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msg/google-code/-/0wcAh_39XbgJ.
For more options, visit https://groups.google.com/groups/opt_out.