454,385 Members | 1,739 Online
Need help? Post your question and get tips & solutions from a community of 454,385 IT Pros & Developers. It's quick & easy.

# calculating 2^601 results in "1.#INF00"

 P: 14 I am trying to find 2 at the power of 601, but my calculator doesn't have a large enough screen, so I decided to make a program for my computer to do this, but when I get to a high number the computer only prints : 1.#INF00. Is there any way to do it? My code is the fallowing: Expand|Select|Wrap|Line Numbers  #include   #include  #include    using namespace std; float a; float x; float y;   main() { x=2; y=601; a = pow(x,y); printf("%f",a); cin.get(); }    May 23 '07 #1
22 Replies

 100+ P: 1,806 2^601 is (VERY) very very very large..... I suspect this number is two big for any of the primitives (I suspect even 2^100 is probably too large) May 23 '07 #2

 100+ P: 1,806 Others have come accross this problem before, you may like to take a look at this May 23 '07 #3

 P: 14 Others have come accross this problem before, you may like to take a look at this I'm trying to compile the NTL program but this is the answer I get from the compiler: [Linker error] undefined reference to `touch_double(double*)' [Linker error] undefined reference to `val_double(double)' [Linker error] undefined reference to `val_double(double)' [Linker error] undefined reference to `touch_double(double*)' [Linker error] undefined reference to `val_double(double)' and etc.., what do I have to do? May 24 '07 #4

 100+ P: 1,806 It sounds like you have included the appropriate header files, but the compiler can't find the code ( .cpp) files. You need to specify the path to the source files as well as to the headers If you are using an IDE, this is as easy as making sure that the src folder is in the search path for the compiler May 24 '07 #5

 P: 14 I downloaded WinNTL 5.4.1 and unzipped it in C:\ and Now I'm trying to Compile the Program but I have a hard time doing so (Even though I fallow the Instructions) could you or anybody try Compiling it, and after that guide me through the steps? I can use the IDE Dev-C++ and MinGW(Minimal GNU for Windows) as Compilers. Thanks, Alex May 24 '07 #6

 100+ P: 1,806 Could you please list some of the errors you are getting, the files you are including.... You can actually add each file (including the .cpp) to your project, ro you can go to the directories option under project options and add the directories these files are in May 24 '07 #7

 P: 14 The Installation instructions of the program told me to compile everyting in the src directory, and create a static library, which I did with Dev-C++ IDE, everything went well with the compilation, but It created a ".a" file instead of a ".lib" file. So this is why I asked you to try it if you want, and then show me how, or if you already know how. Thanks May 24 '07 #8

 100+ P: 1,806 A .a is much the same thing as a .lib.... in Dev go to "Project Options", select the "Parameters" Tab, Click "Add Library or Object" (lower Right Hand Side), and browse through to find your .a May 24 '07 #9

 P: 14 Thanks the compilation works fine, I compiled my program with the fallowing codes: Expand|Select|Wrap|Line Numbers  #include   #include  #include  #include  #define NTL_NO_MIN_MAX ;   using namespace std; float a; float x; float y;   main() { x=2; y=601; a = pow(x,y); printf("%f",a); cin.get(); }   With the "ntl.a" file included also in Project Options, and the src folder in the search path, but my program stills print "1.#INF00". Do you know of any other way? May 25 '07 #10

 100+ P: 1,806 I must admit I've not actually used the library, so I'm not sure how it would be used, but I will look into it if I get a chance. May 25 '07 #11

 100+ P: 1,806 here are some examples that may help you: Large Floating point numbers: Expand|Select|Wrap|Line Numbers #include    int main() {    RR acc, val; //use RR to declare big floats      acc = 0;    while (SkipWhiteSpace(cin)) {       cin >> val;       acc += val*val;  //use c in and cout rather than prinf    }      cout << acc << "\n"; }     Large integers: Expand|Select|Wrap|Line Numbers #include    NTL_CLIENT   int main() {    ZZ a, b, c;  //use ZZ to declare ints      cin >> a;     cin >> b;     c = (a+1)*(b+1);    cout << c << "\n";  //use cin cout to use input and output with these types }     May 25 '07 #12

 P: 14 Thanks it works! And by the way does anybody know how to display large numbers without scientific notations? Expand|Select|Wrap|Line Numbers  #include   #include    #include    #define NTL_NO_MIN_MAX   using namespace std; NTL_CLIENT     int main() { RR a, x, y;     x=2; y=33; a = pow(x,y); cout<

 P: 79 You can use the manipulators in the iomanip header file. Also read up on the printf formats...they can be programmed to display a certain precision. Also, for future reference, there is a 64 bit int that can be defined in C++. I think it's something like: Expand|Select|Wrap|Line Numbers __int64 May 25 '07 #14

 P: 14 How would that go in my program? My Program is on the reply just before your's. May 25 '07 #15

 P: 79 It's been a while since I used them, and I don't have time right now to do it for you. Here is a link to my old class notes for C++ http://www.sce.carleton.ca/courses/e...hapter%204.pdf Jump to pages 16-20 for the output manipulators. The professor that wrote these is excellent and makes everything very simple. May 25 '07 #16

 100+ P: 1,806 A 64 bit int gives you 2^64 values.... May 25 '07 #17

 P: 1 float is too small for the result of 2^602 try this replace float a; float x; float y; for double a; double x; double y; or long double a; long double x; long double y; May 26 '07 #18

 100+ P: 1,806 which is why the NTL (Number Theory Library) was introduced earlier in this thread May 26 '07 #19

 P: 14 It's been a while since I used them, and I don't have time right now to do it for you. Here is a link to my old class notes for C++ http://www.sce.carleton.ca/courses/e...hapter%204.pdf Jump to pages 16-20 for the output manipulators. The professor that wrote these is excellent and makes everything very simple. Thanks for your texts, it works but not with NTL, since with the setiosflags(ios::fixed) function only type double is accepted. Does anybody know of a way that is compatible with NTL? Jun 4 '07 #20

 100+ P: 1,806 NTL should support large integer arithmetic using ZZ...... does this print in exponential notation? Jun 4 '07 #21

 P: 14 NTL should support large integer arithmetic using ZZ...... does this print in exponential notation? Thanks, It Works Perfectly Now! Though I had to change the pow function and make one of my own that would work with NTL, But Now my program works just as I wanted! Thanks to everybody who helped me! Alexandre Proulx http://www.alprogramming.wetpaint.com www.alprogramming.wetpaint.com Jun 11 '07 #22

 100+ P: 1,806 That's what (most of us) are here for.... Jun 11 '07 #23