944,164 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4440
  • C++ RSS
May 1st, 2005
0

big numbers in C++ 5.4455e07

Expand Post »
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) ??
Similar Threads
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
May 1st, 2005
0

Re: big numbers in C++ 5.4455e07

Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 1st, 2005
0

Re: big numbers in C++ 5.4455e07

oh ok...so 4.89281e+07 is 48,928,100 ?

thanks
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
May 1st, 2005
0

Re: big numbers in C++ 5.4455e07

>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:
C++ Syntax (Toggle Plain Text)
  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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 1st, 2005
0

Re: big numbers in C++ 5.4455e07

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:

C++ Syntax (Toggle Plain Text)
  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)
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
May 1st, 2005
0

Re: big numbers in C++ 5.4455e07

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 1st, 2005
0

Re: big numbers in C++ 5.4455e07

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
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Cube Root Calculator
Next Thread in C++ Forum Timeline: Inheritance and Polymorphism





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC