This project is read-only.


As the Microsoft .NET Framework contains a lot of members that implements arithmetic operators and Academy.Numerics contains also an interface to define basic arithmetic operations (IArithmeticallyOperable), a class to ease the work is needed.
That’s why Academy.Numerics has ArithmeticOperator, this is an abstract class that represents the base object for all IArithmeticOperator implementations. To define an IArithmeticOperator you can both, implement the interface directly or inherit from ArithmeticOperator.
Anyway, the main objective of this class is the implementation provided by the Default property. If you have a member that implements IArithmeticallyOperable or defines arithmetic operators like +, -, *, / and %. Then you don’t have to implement that code again to integrate the member to Academy.Numerics. Next code uses the Integer object defined in the IArithmeticallyOperable section, and the Microsoft .NET Framework’s Int32 struct, to demonstrate this approach.
static void Main(string[] args)
    ArithmeticOperator op = ArithmeticOperator.Default;

    Integer integerLeft = new Integer(16);
    Integer integerRight = new Integer(4);

    Console.WriteLine("Using \"Integer\" definition");
    Console.WriteLine("Integer left value: \t{0}", integerLeft);
    Console.WriteLine("Integer right value: \t{0}", integerRight);
    Console.WriteLine("Sum: \t\t{0}", op.Add(integerLeft, integerRight));
    Console.WriteLine("Subtract: \t{0}", op.Subtract(integerLeft, integerRight));
    Console.WriteLine("Multiply: \t{0}", op.Multiply(integerLeft, integerRight));
    Console.WriteLine("Divide: \t{0}", op.Divide(integerLeft, integerRight));
    Console.WriteLine("Mod: \t\t{0}", op.Mod(integerLeft, integerRight));

    int int32Left = 16;
    int int32Right = 4;
    Console.WriteLine("\nUsing \"Int32\" definition");
    Console.WriteLine("Int32 left value: \t{0}", int32Left);
    Console.WriteLine("Int32 right value: \t{0}", int32Right);
    Console.WriteLine("Sum: \t\t{0}", op.Add(int32Left, int32Right));
    Console.WriteLine("Subtract: \t{0}", op.Subtract(int32Left, int32Right));
    Console.WriteLine("Multiply: \t{0}", op.Multiply(int32Left, int32Right));
    Console.WriteLine("Divide: \t{0}", op.Divide(int32Left, int32Right));
    Console.WriteLine("Mod: \t\t{0}", op.Mod(int32Left, int32Right));

Using "Integer" definition
Integer left value: 16
Integer right value: 4
Sum: 20
Subtract: 12
Multiply: 64
Divide: 4
Mod: 0

Using "Int32" definition
Int32 left value: 16
Int32 right value: 4
Sum: 20
Subtract: 12
Multiply: 64
Divide: 4
Mod: 0

Last edited Jul 26, 2013 at 3:29 AM by rathmA, version 1


No comments yet.