   Longest C++ Variable (other topic seemed to have deleted itself)
  I decided to impress my friends by implementing the Gauss Formula in a C++ program. (For all of you who don''t know, the Gauss Formula is getting the sum of numbers to a number i.e. 1+2+3...+n) and I wanted to find the sum of numbers in 1,000,000  or even 1,000,000,000,000 but I do not know any variable longer than an unsigned long int or a double (but I don''t understand the e''s in double). Any ideas?   R.I.P. Mark OsbackSolo Pa Mi GenteVG-Force
  ''long double'' I think.There are math libraries floating around out there with arbitrary precision, too, like this one. ;  Oh, the number after the e is how far to move the decimal place.5.32e+3 is 5320. We move the decimal place left 3 places.4.42e-2 is 0.0442. We move the decimal place right 2 places.xe+y = x*10^y.   [edited by - smart_idiot on February 15, 2004 2:37:03 AM];  You need a BigNum type.   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);quote:Original post by Ekim_Gram  I decided to impress my friends by implementing the Gauss Formula in a C++ program. (For all of you who don''t know, the Gauss Formula is getting the sum of numbers to a number i.e. 1+2+3...+n) and I wanted to find the sum of numbers in 1,000,000  or even 1,000,000,000,000...I hope you don''t actualy plant to use the sum to calculate it.  Since that would be like trying extra hard to make a program slow. You should never let your fears become the boundaries of your dreams. ;  you mean the formula n(n+1)/2  ?if so thats good stuff for a precursor to integration.EDIT: Oh and get a 64 bit cpu and err...write a compiler for 64-bit datatypes.   [edited by - nervo on February 15, 2004 2:55:27 AM];quote:Original post by _DarkWIng_  quote:Original post by Ekim_Gram   I decided to impress my friends by implementing the Gauss Formula in a C++ program. (For all of you who don''t know, the Gauss Formula is getting the sum of numbers to a number i.e. 1+2+3...+n) and I wanted to find the sum of numbers in 1,000,000  or even 1,000,000,000,000...I hope you don''t actualy plant to use the sum to calculate it.  Since that would be like trying extra hard to make a program slow. You should never let your fears become the boundaries of your dreams.   If I was doing that, it wouldn''t be the Gauss Formula. ^_^ And yes, Nervo, n * (n+1)/2. I''m still amazed that the kid was only 5 when he came up with that.   R.I.P. Mark OsbackSolo Pa Mi GenteVG-Force;  Java would seem to be a more appropriate tool for this job. Use big floating point numbers such as double and you''re going to lose precision really quickly. Write the program in Java using the native BigInteger and then write a 1 line C++ program which does nothing more than system( "java c:/projects/java/Gauss" ). Bet they won''t believe you wrote a program to determine infinite size numerical sums, in only one line of C++   code. ;quote:Original post by haro  and then write a 1 line C++ program which does nothing more than system( "java c:/projects/java/Gauss" ).No. Write a shell script. Writing a C++ program to do that would be stupid.   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);quote:Original post by haro  Java would seem to be a more appropriate tool for this job. Use big floating point numbers such as double and you''re going to lose precision really quickly.    It would be nearly as easy to just get a descent large integer library for c++ and use that.  But, however you want to do it... 