I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » New Module Ideas »

robsc\′s Photo
24 Sep 05, 4:14PM
hi, i had better check the data base before posting ;-)

the multiplication algorithm is really nifty, but in my opinion one could still improve your implementation. Obviously the base of any number is not relevant for the calculations we perform on that number. So why don't take the (8-bit-long) characters of a string and use them as base-256 digits ? In doing so, we can easily perform simple arithmetics (like addition) on these digits without converting them back to ordinary doubles or integers.

#include <iostream>
using namespace std;
int main()
{
        char a,b;
        a =  12;
        b =  79;
 
        //the  conversion to short is not really good, it will produce negative 
        //numbers for sums greater than 127
        cout <<short(a+b)<<endl;
        return(0);
}

Of course, then there have to be means of converting the number back to a human-readable base, but that can be done very efficiently.

That is of course not my idea, i've taken it from [url=www.library.cornell.edu/nr]Numerical Recipes in C .

What you said about overloading functions in the code cogs database would be much simpler if we had a defined type (i.e. a class) that overloads arithmetic operators. In this vein you avoid rewriting the entire code and replacing "a+b" by "add(a,b)" and so on.

robert
Currently you need to be logged in to leave a message.