| | |
big numbers in C++ 5.4455e07
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
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) ??
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) ??
>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:
Yep, sure seems that way.
Well, it takes a bit of work to do the commas, but let's see:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <locale> #include <string> using namespace std; class numfmt: public numpunct<char> { string do_grouping() const { return "\3"; } char_type do_thousands_sep() const { return ','; } }; int main() { cout.imbue ( locale ( locale(), new numfmt ) ); cout<< fixed << 4.89281e+07 <<endl; }
I'm here to prove you wrong.
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
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:
well, i get a whole bunch of those numbers, but no precision ...
grrrrrr .... and this isnt even for a CS class (discrete math 2)
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)
#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; 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; } output: -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 x = 37666 y = 4.89281e+07 z = 5.52878e+12 x = 4.89281e+07 y = 5.52878e+12 z = 8.11538e+20 x = 5.52878e+12 y = 8.11538e+20 z = 1.34604e+34 x = 8.11538e+20 y = 1.34604e+34 z = 3.2771e+55 x = 1.34604e+34 y = 3.2771e+55 z = 1.32333e+90 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)
Well, if you want to force precision, add the blue line:
But you'll probably just get a ton of zeros instead of anything useful.
#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;
} I'm here to prove you wrong.
![]() |
Similar Threads
- factoring function for large numbers (C++)
- Store large numbers in C (C++)
- storing large numbers (C++)
Other Threads in the C++ Forum
- Previous Thread: Cube Root Calculator
- Next Thread: Inheritance and Polymorphism
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






