Fundamentals
Learn about the fundamentals of Mathematics.NET below.
Numeric Types
All numeric types in Mathematics.NET implement the IComplex interface. Unlike INumberBase, this interface defines the method Conjugate, which makes operations that accept either complex or real numbers as parameters more robust. To create a numeric type, users must also specify a backing type that implements the IBinaryNumber interface. This means int, BigInteger, and double are all valid backing types.
Complex Numbers
Complex numbers are represented by the Complex type. Basic methods and properties made available include Conjugate, Magnitude, and Phase. To create a complex number, write
Complex<double> z = new(1.23, 4.56);
Real Numbers
Real numbers are represented by the Real type. It implements the IReal interface, which inherits from IComplex, and contains additional methods such as Max and Min. To create a real number, write
Real<double> x = new(1.23);
Rational Numbers
Rational numbers are represented by the Rational type. This type implements the IRational interface, which inherits from IReal, and contains addition methods such as Reciprocate and GCD. Rationals accept any backing type that implements the IBinaryInteger and ISignedNumber interfaces. This includes BigInteger, which should be used carefully due to its performance implications.
Methods and properties made available include Num, Den, Reduce, and Reciprocate. To create a rational number, write
Rational<int, double> r = new(1, 2);
Rationals also have a second generic type parameter that accepts any value that implements the IBinaryFloatingPointIeee754 interface. This allows for methods such as Norm to return valid results.