diff --git a/src/Mathematics.NET/Core/IReal.cs b/src/Mathematics.NET/Core/IReal.cs index 5fff79b2..e48ec194 100644 --- a/src/Mathematics.NET/Core/IReal.cs +++ b/src/Mathematics.NET/Core/IReal.cs @@ -46,6 +46,16 @@ public interface IReal /// The backing value of the type double Value { get; } + /// Compute the ceiling function of a value + /// A value + /// The smallest integer greater than or equal to the value + static abstract T Ceiling(T x); + + /// Compute the floor function of a value + /// A value + /// The largest integer less than or equal to the value + static abstract T Floor(T x); + /// Check if a value is negative infinity /// The value to check /// true if the value is negative infinity; otherwise, false diff --git a/src/Mathematics.NET/Core/Rational.cs b/src/Mathematics.NET/Core/Rational.cs index c8a3a71f..2250c7e0 100644 --- a/src/Mathematics.NET/Core/Rational.cs +++ b/src/Mathematics.NET/Core/Rational.cs @@ -436,8 +436,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static Rational Abs(Rational x) => new(T.Abs(x._numerator), T.Abs(x._denominator)); + public static Rational Ceiling(Rational x) + { + var (quotient, remainder) = T.DivRem(x._numerator, x._denominator); + return remainder == T.Zero ? quotient : quotient + T.One; + } + public static Rational Conjugate(Rational x) => x; + public static Rational Floor(Rational x) => T.DivRem(x._numerator, x._denominator).Quotient; + public static Rational FromDouble(double x) => (Rational)x; public static Rational FromReal(Real x) => (Rational)x; diff --git a/src/Mathematics.NET/Core/Real.cs b/src/Mathematics.NET/Core/Real.cs index 3c58d124..2ec49d84 100644 --- a/src/Mathematics.NET/Core/Real.cs +++ b/src/Mathematics.NET/Core/Real.cs @@ -260,8 +260,12 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static Real Abs(Real x) => Math.Abs(x._value); + public static Real Ceiling(Real x) => Math.Ceiling(x._value); + public static Real Conjugate(Real x) => x; + public static Real Floor(Real x) => Math.Floor(x._value); + public static Real FromDouble(double x) => new(x); public static Real FromReal(Real x) => x;