diff --git a/BeefLibs/corlib/src/Double.bf b/BeefLibs/corlib/src/Double.bf index e6f30a14..9e4d11bf 100644 --- a/BeefLibs/corlib/src/Double.bf +++ b/BeefLibs/corlib/src/Double.bf @@ -10,11 +10,14 @@ namespace System using System.Diagnostics; #unwarn - public struct Double : double, IFloating, ISigned, IFormattable, IHashable, ICanBeNaN, IParseable + public struct Double : double, IFloating, ISigned, IFormattable, IHashable, ICanBeNaN, IParseable, IMinMaxValue { public const double MinValue = -1.7976931348623157E+308; public const double MaxValue = 1.7976931348623157E+308; + public static double IMinMaxValue.MinValue => MinValue; + public static double IMinMaxValue.MaxValue => MaxValue; + // Note Epsilon should be a double whose hex representation is 0x1 // on little endian machines. public const double Epsilon = 4.9406564584124654E-324; diff --git a/BeefLibs/corlib/src/Float.bf b/BeefLibs/corlib/src/Float.bf index 3ecfae64..be3e3ba1 100644 --- a/BeefLibs/corlib/src/Float.bf +++ b/BeefLibs/corlib/src/Float.bf @@ -3,7 +3,7 @@ using System.Globalization; namespace System { #unwarn - struct Float : float, IFloating, ISigned, IFormattable, IHashable, IEquatable, ICanBeNaN, IParseable + struct Float : float, IFloating, ISigned, IFormattable, IHashable, IEquatable, ICanBeNaN, IParseable, IMinMaxValue { public const float MinValue = (float)-3.40282346638528859e+38; public const float Epsilon = (float)1.4e-45; @@ -12,6 +12,9 @@ namespace System public const float NegativeInfinity = -1.0f / 0.0f; public const float NaN = 0.0f / 0.0f; + public static float IMinMaxValue.MinValue => MinValue; + public static float IMinMaxValue.MaxValue => MaxValue; + // We use this explicit definition to avoid the confusion between 0.0 and -0.0. public const float NegativeZero = (float)-0.0; diff --git a/IDEHelper/Tests/src/Floats.bf b/IDEHelper/Tests/src/Floats.bf index d9853198..2bc54bab 100644 --- a/IDEHelper/Tests/src/Floats.bf +++ b/IDEHelper/Tests/src/Floats.bf @@ -50,5 +50,20 @@ namespace Tests FloatParseErrTest("6E+"); FloatParseErrTest("6e+"); } + + public static void MinMaxTest(T expectedMinValue, T expectedMaxValue) + where T : IMinMaxValue + where int : operator T <=> T + { + Test.Assert(T.MinValue == expectedMinValue); + Test.Assert(T.MaxValue == expectedMaxValue); + } + + [Test] + public static void TestMinMax() + { + MinMaxTest(Float.MinValue, Float.MaxValue); + MinMaxTest(Double.MinValue, Double.MaxValue); + } } }