Click here to Skip to main content
Click here to Skip to main content

Member :: Memory-Wide-Number

By , 15 Apr 2013
 

Introduction

Have you ever wanted to overcome integer boundaries? If at least one time had you thought of multiplying or dividing a million digit by another, you're welcome. You're at the right place. You will make easy use of the TMember type: a Member object.

Code Usage

  • It is so easy to initialize a Member object:
  • m1 = TMember.FromString(txtTerm1.Text, new TRadix(10));
    m2 = TMember.FromString(txtTerm2.Text, new TRadix(10));
    uint n = 543215;
    TMember m3 = TMember.FromInt(n, new TRadix(10));
  • Now you can initialize your Member instance with various radixes, like this one:
  • uint[] data1 = new uint[456];
    uint[] data2 = new uint[456];
    for (int i = 0; i < 456; i++)
    {
      data1[i] = (uint)(i * i);
      data2[i] = (uint)(i * i%17);
    }
    m1 = TMember.FromData(data1, new TRadix(uint.MaxValue));
    m2 = TMember.FromData(data2, new TRadix(uint.MaxValue));
  • You can also make conversion of different radixes to or from decimal using the ToDecimal and DecimalToRadix methods. They're public now:
  • TMember mhex = TMember.FromString("4321543254362", new TRadix(16));
    TMember mbinary = mhex.ToDecimal().DecimalToRadix(new TRadix(2));
  • I implemented nearly all operators valid for integers:
  • public static TMember operator +(TMember term1, TMember term2)
    public static TMember operator +(TMember term1, TDigit term2)
    public static TMember operator -(TMember term1, TMember term2)
    public static TMember operator -(TMember term1, TDigit term2)
    public static TMember operator *(TMember term1, TMember term2)
    public static TMember operator *(TMember term1, TDigit term2)
    public static TMember operator /(TMember term1, TMember term2)
    public static TMember operator /(TMember term1, TDigit term2)
    public static TMember operator %(TMember term1, TMember term2)
    public static TMember operator %(TMember term1, TDigit term2)
    public static TMember operator <(TMember term1, TMember term2)
    public static TMember operator <(TMember term1, TDigit term2)
    public static TMember operator >(TMember term1, TMember term2)
    public static TMember operator >(TMember term1, TDigit term2)
    public static TMember operator <=(TMember term1, TMember term2)
    public static TMember operator <=(TMember term1, TDigit term2)
    public static TMember operator >=(TMember term1, TMember term2)
    public static TMember operator >=(TMember term1, TDigit term2)
    public static TMember operator ==(TMember term1, TMember term2)
    public static TMember operator ==(TMember term1, TDigit term2)
  • And you can make use of it:
  • txtResult.Text = "" + (m1 * m2) % TMember.FromString("54366");
  • The result is simple to see; not so easy to evaluate, however:
  • Member/program-output.PNG

Architecture

  • The code architecture could be summarized as below:
  • Member/SolutionExplorer.PNG

  • In the Arithmetics namespace, the SCalculator class is the transition layer to the outside of the namespace. It initializes all TAdder, TComparer etc. classes as static object instances and Types classes make use of them like this:
  • return SCalculator.Comparer.Gt(term1, term2);
  • As you can see, this code compares two values if term1 > term2 and returns the result.
  • The Types namespace has these core types for Member:
    • TMember: main entry class
    • TDigit: represents one digit of a number (with any radix)
    • TRadix: represents radix for digit and member
    • ESigns: for now, this enumeration is orphan
  • The Constraints namespace is my favorite. Imagine a validator of any type making checks and returning the checked type in one line of code:
  • uint n = 3;
    n = SValidator<uint>.Validate(num => num > 10, n);
  • This line of code validates n if it is greater than or equal to (>=) 0 (now that is false because n=3). If not, it throws an exception. And here is a some more complicated example (trick: you can check if the string has only decimal digits):
  • numstr=SValidator<string>.Validate(s => s.All<char>(ch => Char.IsNumber(ch)), numstr);

    I love it Smile | :)

  • There is also another class TSelfValidator<TType> to validate derived classes, but that's enough explanation. If you're still with me, I appreciate your patience. Don't get afraid. I am almost finished.
  • Member/ClassDiagram.PNG

Last Word

  • I strongly advice you to look over my code if you're interested in using it. Mathematics imply. Computers reply.

History

  • 2013.04.15  This version fixes not starting error. And adds start over button. 
  • 2011.06.11: This version supports radix conversion using the DecimalToRadix and ToDecimal methods.
  • 2011.06.10: This version does not provide support for floating number implementation. m1 / m2 simply returns m1 // m2 (true div: remainder trimmed).

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

lampiclobe
Software Developer
Turkey Turkey
Member
I am a software developer emphasizing algorithm side of development.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4professionaljfriedman15 Apr '13 - 10:42 
GeneralRe: My vote of 4memberlampiclobe16 Apr '13 - 3:43 
GeneralRe: My vote of 4professionaljfriedman16 Apr '13 - 3:49 
GeneralMy vote of 5memberHalil ibrahim Kalkan9 Jun '11 - 19:54 
GeneralRe: My vote of 5 [modified]memberdr.ozgur.sonmez10 Jun '11 - 2:26 
GeneralHave you seen BigInteger structure?memberPaulo Zemek9 Jun '11 - 11:03 
GeneralRe: Have you seen BigInteger structure?memberdr.ozgur.sonmez10 Jun '11 - 0:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 15 Apr 2013
Article Copyright 2011 by lampiclobe
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid