Hi mates ive made a program that is supposed to count 93^16 and its really not a complicated program.
But i have this small problem when it is going to write 74805201 it writes 7.48052e+007 and i know its some really clever formula or something.
Does anyone know of a way for me to get it to write the digits and not the formula. (it needs to be able to handle 2.70828e+035 and if possible 9.80515e+062)
And if you feel like it could you please explain how that formula thing works or maybe give me a link to a page where i can read a bit about it.
P.S Thanks for any help on forehand and if you want me to post the code just write so.
i think my double is to small
Started by Nille, Oct 18 2007 09:19 AM
8 replies to this topic
#1
Posted 18 October 2007 - 09:19 AM
|
|
|
#2
Posted 18 October 2007 - 12:07 PM
I can't explain the formula (look complicated) but I think using a long double would solve your problem.
Is a float or double larger?
Is a float or double larger?
#3
Posted 19 October 2007 - 12:15 AM
You won't be able to count in 1's via a floating point representation because there's a limit on precision. The floating point numbers are ordered float (or single precision float), double, and long double in terms of both precision and range of representable numbers.
Floating point - Wikipedia, the free encyclopedia
For integers of that size you really want an infinite precision number which doesn't exist in standard C or C++. Unsigned 64bit integers can go up to ~10^19. You can either create a class to handle infinite precision integers (including output) if you are using C++. For C you could achieve the same but I'd be messier. Personally I'd look at a moth mathematical oriented language like Haskell. Developing an infinite precision integer in C/C++ is going to be messy and require a whole lot of memory management.
Floating point - Wikipedia, the free encyclopedia
For integers of that size you really want an infinite precision number which doesn't exist in standard C or C++. Unsigned 64bit integers can go up to ~10^19. You can either create a class to handle infinite precision integers (including output) if you are using C++. For C you could achieve the same but I'd be messier. Personally I'd look at a moth mathematical oriented language like Haskell. Developing an infinite precision integer in C/C++ is going to be messy and require a whole lot of memory management.
#4
Posted 19 October 2007 - 03:02 AM
So basicly use smaller numbers or use another langage? :P
#5
Posted 19 October 2007 - 03:13 AM
Like G_Morgan said, you can't represent numbers as big as 31313180170800116587336013460801, which 93^16 is, with standard-C++-types. You need to fix some solutions yourself, or use some of the many big-integer libraries for C++. Use some search engine, and you'll find something fast.
#6
Posted 19 October 2007 - 08:14 AM
If you use the GMP library, you will be able to accomplish what you want.
#7
Posted 19 October 2007 - 03:45 PM
I didn't think you understood what '7.48052e+007' meant. Just to clarify, it means the number 7.48052 x 10^7 (move the decimal 7 places to the right ->) or 7.4805200. Though you'd like to know :)
#8
Posted 20 October 2007 - 03:13 AM
Victor said:
I didn't think you understood what '7.48052e+007' meant. Just to clarify, it means the number 7.48052 x 10^7 (move the decimal 7 places to the right ->) or 7.4805200. Though you'd like to know :)
Not to be pedantic but you mean 74805200 ;).
#9
Posted 20 October 2007 - 11:39 AM


Sign In
Create Account


Back to top









