Re: Fibonacci numbers

From: Ivan Vecerina (NONE_use_form_at_website_to_contact_me)
Date: 10/10/03


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


Relevant Pages

  • Re: Null-terminated strings: the final analysis.
    ... irrelevant to a discussion of C strings. ... contain any characters other than '\0', ... Yes, but you can't store a null character in the middle of a string, ... If, because of some requirement outside the C language, I want to ...
    (comp.lang.c)
  • Re: bigint queston C++ classes
    ... I suggest an array of unsigned char, or unsigned short, or perhaps unsigned ... You'll need ceil/log) base-b digits to store x, ... these are not strings, ...
    (comp.programming)
  • Re: Sorting Question for Marshall Barton (Contd)
    ... begin with numbers and strings that begin with characters. ... pad to 8 digits and sort. ... If the string has non-numeric characters in the ...
    (microsoft.public.access.reports)
  • Re: Reading an Ascii string
    ... I have big legacy files that stores various values (ints, bytes, strings) ... The strings are stored as Ascii in the file, ... the rest are the Ascii characters. ... I'll get rid of the text box and store them directly in the database. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Validation Rules???
    ... Don't try to store a telephone number in a numeric field. ... store numbers as strings of digits but as binary-coded numeric values, ... treat it as a string of digits and store it in a text field. ... add more elements to the validation rule - ...
    (microsoft.public.access.tablesdbdesign)