Re: Fibonacci numbers
From: Ivan Vecerina (NONE_use_form_at_website_to_contact_me)
Date: 10/10/03
- Next message: glen stark: "function pointer and member function pointer question"
- Previous message: David B. Held: "Re: News Test"
- In reply to: Joost Ronkes Agerbeek: "Re: Fibonacci numbers"
- Next in thread: Ryan Winter: "Re: Fibonacci numbers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 10 Oct 2003 12:12:59 +0200
"Joost Ronkes Agerbeek" <joost@ronkes.nl> wrote in message
news:3f865d99$0$58700$e4fe514c@news.xs4all.nl...
| You will have to write your own class for that and overload the arithmic
| operators, especially the + in your case.
|
| Of course there is the question of how to store the number. One way to do
| it, is to store it as a string. It might not be the most efficient way in
| terms of memory and speed, but it does make the implementation
| straight-forward. Initialization is also clean, just write:
| Huge("123456789");
|
| Another way to do it is to use multiple ints (or longs) to store the
number.
| You could probably implement this more efficiently than with strings, but
I
| think it makes the code a bit more complicated.
Not necessarily more complicated.
Instead of using characters to represent decimal digits, you can use
short integers that store a base 10000 digit (0 to 9999).
(this keeps the product of two such digits in range for 'long').
It is easier than dealing with characters, as you don't need to offset
the values by '0' everywhere. Printing the number is also simple enough.
Also, for many computations, it is easier to manipulate the numbers in
little-endian format (units to the left/lower adresses), rather than
the way that we write numbers in strings (units at the end).
std::vector<int> is an option to store such a number...
Regards,
-- http://ivan.vecerina.com
- Next message: glen stark: "function pointer and member function pointer question"
- Previous message: David B. Held: "Re: News Test"
- In reply to: Joost Ronkes Agerbeek: "Re: Fibonacci numbers"
- Next in thread: Ryan Winter: "Re: Fibonacci numbers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|