Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public static fields | List of all members
Loyc.Math.Maths< T > Class Template Reference

This class helps generic code to perform calculations on numbers of unknown type, by providing access to various math interfaces. More...


Source file:

Remarks

This class helps generic code to perform calculations on numbers of unknown type, by providing access to various math interfaces.

Template Parameters
TA numeric type.

If a certain math interface is not available for a certain type, then the corresponding field will be null. For example, Maths<int>.FloatMath is null because int is not floating-point. The Traits, Math, and related properties will be null for non-numeric types.

TODO: support non-builtin types!

Generic code that uses Maths<T> is slower than code that uses a generic parameter with a math constraint. That's because generic struct parameters are early-bound and can be inlined, while calls through an interface such as IMath<T> are normal late-bound interface calls and cannot be inlined. Compare the two examples below.

// Calculates the length of a vector with magnitude (x, y): // Slower version based on Maths<T>. Example: Length(3.0,4.0) public T Length<T>(T x, T y) { var m = Maths<T>.Math; return m.Sqrt(m.Add(m.Square(x), m.Square(y))); }

// Calculates the length of a vector with magnitude (x, y): // Faster version based on Maths<T>. Unfortunately, this version is // inconvenient to call because the caller must specify which math // provider to use. Example: Length<double,MathD>(3.0,4.0) public T Length<T,M>(T x, T y) where M:struct,IMath<T> { var m = default(M); return m.Sqrt(m.Add(m.Square(x), m.Square(y))); }

Public static fields

static readonly INumTraits< T > Traits = Get() as INumTraits<T>
 
static readonly IMath< T > Math = Get() as IMath<T>
 
static readonly ISignedMath< T > SignedMath = Get() as ISignedMath<T>
 
static readonly IUIntMath< T > UIntMath = Get() as IUIntMath<T>
 
static readonly IIntMath< T > IntMath = Get() as IIntMath<T>
 
static readonly IRationalMath< T > RationalMath = Get() as IRationalMath<T>
 
static readonly IFloatMath< T > FloatMath = Get() as IFloatMath<T>
 
static readonly IComplexMath< T > ComplexMath = Get() as IComplexMath<T>
 
static readonly IConvertTo< T > NumConverter = Get() as IConvertTo<T>
 
static readonly IOrdered< T > Ordered = Get() as IOrdered<T>
 
static readonly IIncrementer< T > Inrementer = Get() as IIncrementer<T>
 
static readonly IBitwise< T > Bitwise = Get() as IBitwise<T>
 
static readonly IBinaryMath< T > BinaryMath = Get() as IBinaryMath<T>
 
static readonly IAdditionGroup< T > AdditionGroup = Get() as IAdditionGroup<T>
 
static readonly ITrigonometry< T > Trigonometry = Get() as ITrigonometry<T>
 
static readonly IHasRoot< T > HasRoot = Get() as IHasRoot<T>
 
static readonly IExp< T > Exp = Get() as IExp<T>
 
static readonly IMultiply< T > Multiply = Get() as IMultiply<T>
 
static readonly
IMultiplicationGroup< T > 
MultiplicationGroup = Get() as IMultiplicationGroup<T>
 
static readonly IRing< T > Ring = Get() as IRing<T>
 
static readonly IField< T > Field = Get() as IField<T>