/* These interfaces can be used to make types that support arithmetic operations usable for generics. You might want to use explicit interface implementations. All basic data types such as sbyte,short,int,long,float,double,decimal should implement the IArithmetic interface. Types like string that only support the + operator should only implement IAddable and maybe IHasZero. */ namespace System.Generic { /// /// Every class that defines a + operation /// like T operator + (T a,T b) should consider /// implementing this interface. /// public interface IAddable { /// /// Returns the sum of the object and . /// It must not modify the value of the object /// /// The second operand /// the sum T Add(T a); } /// /// Every class that defines a - operation /// like T operator - (T a,T b) should consider /// implementing this interface. /// public interface ISubtractable { /// /// Returns the difference of the object and . /// It must not modify the value of the object /// /// The second operand /// the difference T Subtract(T a); } /// /// Every class that has a + operation and an element /// such that x+e = e+x = x for all x should consider implementing this /// interface. If T is a ValueType, e should be the default value. /// public interface IHasZero : IAddable { /// /// Returns the neutral element of addition /// /// e T Zero { get; } } /// /// Every class that defines a unary - operation /// such that x+(-x)=e and -(-x)=x should consider /// implementing this interface. /// public interface INegatable : IAddable, ISubtractable, IHasZero { /// /// Returns the negative of the object. Must not modify the object itself. /// /// The negative T Negative(); } /// /// Every class that defines a * operation /// like T operator * (T a,T b) should consider /// implementing this interface. /// public interface IMultipliable { /// /// Returns the product of the object and . /// It must not modify the value of the object /// /// The second operand /// the product T Multiply(T a); } /// /// Every class that defines a / operation /// like T operator / (T a,T b) should consider /// implementing this interface. /// public interface IDivisible { /// /// Returns the quotient of the object and . /// It must not modify the value of the object /// /// The second operand /// the quotient T Divide(T a); } /// /// Every class that has a * operation and an element /// such that x*e = e*x = x for all x should consider implementing /// this interface. /// /// public interface IHasOne : IMultipliable { /// /// Returns the neutral element of multiplication /// /// e T One { get; } } /// /// Every class that defines an unary inverse operation such that /// x*inverse(x)~=e and inverse(inverse(x))~=x for all x except Zero /// should consider implementing this interface. /// Types that might want to implement this would be float, double, decimal, /// but not short,int,long. /// /// public interface IInvertible : IMultipliable, IDivisible, IHasOne { /// /// Returns the inverse /// /// the inverse T Inverse(); } /// /// Every class that defines the standard arithmetic operations +,-,*,/ should /// consider implementing this interface. This interface does not contain /// IInvertible because some arithmetic types such as int, long etc. do not have /// an inverse as defined in IInvertible. /// /// interface IArithmetic : IAddable, ISubtractable, IHasZero, INegatable, IMultipliable, IDivisible, IHasOne { } }