By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,385 Members | 1,739 Online
Bytes IT Community
+ Ask a Question
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
  1.  #include <iostream> 
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6. float a;
  7. float x;
  8. float y;
  9.  
  10. main()
  11. {
  12. x=2;
  13. y=601;
  14. a = pow(x,y);
  15. printf("%f",a);
  16. cin.get();
  17.  
May 23 '07 #1
Share this Question
Share on Google+
22 Replies


DeMan
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

DeMan
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

DeMan
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

DeMan
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

DeMan
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
  1.  #include <iostream> 
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <NTL/ZZ.h>
  5. #define NTL_NO_MIN_MAX ;
  6.  
  7. using namespace std;
  8. float a;
  9. float x;
  10. float y;
  11.  
  12. main()
  13. {
  14. x=2;
  15. y=601;
  16. a = pow(x,y);
  17. printf("%f",a);
  18. cin.get();
  19. }
  20.  
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

DeMan
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

DeMan
100+
P: 1,806
here are some examples that may help you:

Large Floating point numbers:
Expand|Select|Wrap|Line Numbers
  1. #include <NTL/RR.h>
  2.  
  3. int main()
  4. {
  5.    RR acc, val; //use RR to declare big floats
  6.  
  7.    acc = 0;
  8.    while (SkipWhiteSpace(cin)) {
  9.       cin >> val;
  10.       acc += val*val;  //use c in and cout rather than prinf
  11.    }
  12.  
  13.    cout << acc << "\n";
  14. }
  15.  
  16.  
Large integers:
Expand|Select|Wrap|Line Numbers
  1. #include <NTL/ZZ.h>
  2.  
  3. NTL_CLIENT
  4.  
  5. int main()
  6. {
  7.    ZZ a, b, c;  //use ZZ to declare ints
  8.  
  9.    cin >> a; 
  10.    cin >> b; 
  11.    c = (a+1)*(b+1);
  12.    cout << c << "\n";  //use cin cout to use input and output with these types
  13. }
  14.  
  15.  
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
  1.  #include <iostream> 
  2. #include <math.h>
  3.  
  4. #include <NTL/RR.h>
  5.  
  6. #define NTL_NO_MIN_MAX
  7.  
  8. using namespace std;
  9. NTL_CLIENT
  10.  
  11.  
  12. int main()
  13. {
  14. RR a, x, y;
  15.  
  16.  
  17. x=2;
  18. y=33;
  19. a = pow(x,y);
  20. cout<<a<< "\n";
  21. cin.get();
  22. }
  23.  
May 25 '07 #13

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
  1. __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

DeMan
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

DeMan
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

DeMan
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

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

Post your reply

Sign in to post your reply or Sign up for a free account.