473,809 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

14 New Member
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
22 6250
DeMan
1,806 Top Contributor
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
1,806 Top Contributor
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
Alexandre Proulx
14 New Member
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
ahammad
79 New Member
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
Alexandre Proulx
14 New Member
How would that go in my program? My Program is on the reply just before your's.
May 25 '07 #15
ahammad
79 New Member
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
1,806 Top Contributor
A 64 bit int gives you 2^64 values....
May 25 '07 #17
hagelbc
1 New Member
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
1,806 Top Contributor
which is why the NTL (Number Theory Library) was introduced earlier in this thread
May 26 '07 #19
Alexandre Proulx
14 New Member
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

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

Similar topics

4
4494
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the difference. I want it to return the difference in years, months, days, hours, minutes and seconds (a complete summary). Keeping into account of course that these are 2 real dates, I dont want it to work with 30.475 as an average number of days in a...
6
9486
by: Stephen Miller | last post by:
Firstly, sorry for the long post, but I've included a fair bit of sample data. Im doing a comparision of 10yr Bond prices and CPI adjustments, with an 18 week moving average of the CPI. I'm using a nested sub-query to calculate the moving average, but I'm having difficulty selecting exactly 18 data points (ie When I include the 'HAVING COUNT(C1.Closes) = 18' line, I get no results). Can anyone help?
0
2276
by: Kasp | last post by:
Hi there, I am trying to make an OLAP cube on a table having two columns (datetime, Number_of_times_an_event_occured). My dimension is time and I want to measure the Min and Max times an event occured over time. I have no problem in calculating Maximum occurance of events over time. However, I have some NULL values in my Number_of_times_an_event_occured column, due to which I don't see any result when I try to calculate
1
4312
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value of txtmonth and the value of txtvalue in another value of txtmonth and the percentage increase . For example if I have the value 1000 in 30/03/03 and the value 1100 in 30/03/04 How do I calculate the difference as 100 and the increase as 10%. I...
3
5346
by: Miller | last post by:
Hi, Can someone tell me how to calculate MFLOPS for the following C# code (on a Pentium 4 2.0 Ghz)? for (i=0; i<n; i++) { for (j=0; j<n; j++) { for (k=0; k<n; k++)
12
9889
by: Larry Bates | last post by:
I'm trying to get the results of binascii.crc32 to match the results of another utility that produces 32 bit unsigned CRCs. binascii.crc32 returns results in the range of -2**31-1 and 2**21-1. Has anyone ever worked out any "bit twiddling" code to get a proper unsigned 32 bit result from binascii.crc32? Output snip from test on three files: binascii.crc32=-1412119273, oldcrc32= 2221277246
5
4176
by: Mr. Ken | last post by:
I am calculating the phase of an IQ signal, which are polluted by AWGN gaussian noise. Thus, near pi/2, direct division of atan(Q/I) may yield outputs either +pi/2 or -pi/2. How do I handle this situation? Thanks.
9
21388
by: clintonb | last post by:
I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by the number of seconds in a day? - Clint
6
1945
by: Avi | last post by:
I need to implement the following calculation: f = (a*b) + (c*d) where a,b,c,d are given double values and f is a double variable for the result I found out that using two different implementations gives two different results: 1) In the first implementation I compute the entire equation in memory 2) In the second implementation I store intermediate to variables, and then load them to compute the final result.
2
59842
jkmyoung
by: jkmyoung | last post by:
Calculating Large Exponents Background: This is a quick article as to how to calculate the exponents of large numbers quickly and efficiently. Starting with a basic multiplication algorithm, it gives subsequently faster algorithms and a few quick examples. The techniques used in this article can be used in general mathematics, encryption, among other things. In this article, the following conventions are used: ^ operator is to mean...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.