1

Here's the question. I need to convert some integer variables to ZZ class or vice verse. How could i do that? I've tried using (ZZ) before the integer or (int) before the ZZ class but all failed.

Wencheng Sun
  • 11
  • 1
  • 2
  • 1
    Any chance you can post the code you are using and what the exact error message is? – chrisaycock Apr 16 '13 at 16:52
  • How about the ZZ before the variable name? That's the normal way to do things. See here for example http://www.shoup.net/ntl/doc/tour-ex1.html – john Apr 16 '13 at 16:55

2 Answers2

2

You haven't posted any code, but I'm sure your question can be answered here, pasted verbatim for your entertainment:

One can also assign a value of type long to a ZZ:

ZZ x;
x = 1;

Note that one cannot write

ZZ x = 1;  // error

to initialize a ZZ. Instead, one could write

ZZ x = conv<ZZ>(1);
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
  • 1
    Thanks a lot! It helps! But what if I want to convert the integer in ZZ back to 'long' type? Here is part of my code. i have mat_ZZ a;( 1 * n) vec_ZZ b; ( 1 element only) what i want to do is to get all the integers in a and b out and then get their reciprocals and finally sort the reciprocals. i don't know how to do using ZZ class. so i want to convert the integers back to 'long' type. How could i achieve this??? thanks very mush! – Wencheng Sun Apr 17 '13 at 15:19
2

A bit late to answer but it might help someone out there. As it was asked in the question

I need to convert some integer variables to ZZ class or vice verse

and also in the comments

what if I want to convert the integer in ZZ back to 'long' type?

Here is the answer, in NTL library the conversion has been provided in tools namespace. Following example demonstrates how to convert from ZZ back to long and vice verse:

ZZ z1 = ZZ(2);
ZZ z2;
long a = 0;
conv(a, z1); //converts zz type to long

conv(z2,a); //converts long to zz type

cout << a; //prints 2

cout << zz2; //prints 2
mr-ma
  • 199
  • 13