big numbers in C++ 5.4455e07

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

big numbers in C++ 5.4455e07

 
0
  #1
May 1st, 2005
ok, call me stupid, maybe i forgot my math:

but if a C++ program spits out this:

-bash-2.05b$ g++ markoff.cpp
-bash-2.05b$ ./a.out
x = 1 y = 1 z = 2
x = 1 y = 2 z = 5
x = 2 y = 5 z = 29
x = 5 y = 29 z = 433
x = 29 y = 433 z = 37666
x = 433 y = 37666 z = 4.89281e+07

what is the number? 4.89281e+07 ???

is it like scientific notation (4.89281 x 10^7) ??
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: big numbers in C++ 5.4455e07

 
0
  #2
May 1st, 2005
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

Re: big numbers in C++ 5.4455e07

 
0
  #3
May 1st, 2005
oh ok...so 4.89281e+07 is 48,928,100 ?

thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: big numbers in C++ 5.4455e07

 
0
  #4
May 1st, 2005
>oh ok...so 4.89281e+07 is 48,928,100 ?
Well, it takes a bit of work to do the commas, but let's see:
  1. #include <iostream>
  2. #include <locale>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class numfmt: public numpunct<char> {
  8. string do_grouping() const { return "\3"; }
  9. char_type do_thousands_sep() const { return ','; }
  10. };
  11.  
  12. int main()
  13. {
  14. cout.imbue ( locale ( locale(), new numfmt ) );
  15. cout<< fixed << 4.89281e+07 <<endl;
  16. }
Yep, sure seems that way.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

Re: big numbers in C++ 5.4455e07

 
0
  #5
May 1st, 2005
hmmm, never seen that code

cuz i was just about to ask how can i get it to be more precise?

so far my code:

  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. double xyz[3];
  6. double mark[3];
  7.  
  8. void markoff(double x, double y, double z)
  9. {
  10. mark[0] = y;
  11. mark[1] = z;
  12. mark[2] = ((3*y*z) - x);
  13.  
  14. cout<<"x = "<<mark[0]<<" y = "<<mark[1]<<" z = "<<mark[2]<<endl;
  15. }
  16.  
  17. int main()
  18. {
  19.  
  20. xyz[0] = 1;
  21. xyz[1] = 1;
  22. xyz[2] = 1;
  23.  
  24. while( mark[2] < (pow(10.0,101.0)) )
  25. {
  26. markoff( xyz[0], xyz[1], xyz[2] );
  27.  
  28. xyz[0] = mark[0];
  29. xyz[1] = mark[1];
  30. xyz[2] = mark[2];
  31. }
  32.  
  33.  
  34. return 0;
  35. }
  36.  
  37.  
  38. output:
  39.  
  40. -bash-2.05b$ ./a.out
  41. x = 1 y = 1 z = 2
  42. x = 1 y = 2 z = 5
  43. x = 2 y = 5 z = 29
  44. x = 5 y = 29 z = 433
  45. x = 29 y = 433 z = 37666
  46. x = 433 y = 37666 z = 4.89281e+07
  47. x = 37666 y = 4.89281e+07 z = 5.52878e+12
  48. x = 4.89281e+07 y = 5.52878e+12 z = 8.11538e+20
  49. x = 5.52878e+12 y = 8.11538e+20 z = 1.34604e+34
  50. x = 8.11538e+20 y = 1.34604e+34 z = 3.2771e+55
  51. x = 1.34604e+34 y = 3.2771e+55 z = 1.32333e+90
  52. x = 3.2771e+55 y = 1.32333e+90 z = 1.30101e+146

well, i get a whole bunch of those numbers, but no precision ...

grrrrrr .... and this isnt even for a CS class (discrete math 2)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: big numbers in C++ 5.4455e07

 
0
  #6
May 1st, 2005
Well, if you want to force precision, add the blue line:
#include <iostream>
#include <math.h>
using namespace std;

double xyz[3];
double mark[3];

void markoff(double x, double y, double z)
{
  mark[0] = y;
  mark[1] = z;
  mark[2] = ((3*y*z) - x);

  cout<<"x = "<<mark[0]<<" y = "<<mark[1]<<" z = "<<mark[2]<<endl;
}

int main()
{

  xyz[0] = 1;
  xyz[1] = 1;
  xyz[2] = 1;

  cout.setf ( ios::fixed, ios::floatfield );
  while( mark[2] < (pow(10.0,101.0)) )
    {
      markoff( xyz[0], xyz[1], xyz[2] );

      xyz[0] = mark[0];
      xyz[1] = mark[1];
      xyz[2] = mark[2];
    }

  return 0;
}
But you'll probably just get a ton of zeros instead of anything useful.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

Re: big numbers in C++ 5.4455e07

 
0
  #7
May 1st, 2005
actually, it printed it out just fine ....

and after all this, i didnt really even need it, as i needed to just count the times ...... well, blah ... oh well, at least i learned something .... kinda
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC