// Copyright (C) 2003 Pedro MartÃnez Juliá <yoros@wanadoo.es>
// Copyright (C) 2004 Novell (http://www.novell.com)
//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System.Runtime.CompilerServices;
+#if NET_2_0
+using System.Runtime.ConstrainedExecution;
+#endif
+
namespace System
{
public sealed class Math
return (result == -0)? 0: result;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static byte Max (byte val1, byte val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static decimal Max (decimal val1, decimal val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static double Max (double val1, double val2)
{
if (Double.IsNaN (val1) || Double.IsNaN (val2)) {
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static float Max (float val1, float val2)
{
if (Single.IsNaN (val1) || Single.IsNaN (val2)) {
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static int Max (int val1, int val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static long Max (long val1, long val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static sbyte Max (sbyte val1, sbyte val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static short Max (short val1, short val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static uint Max (uint val1, uint val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static ulong Max (ulong val1, ulong val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static ushort Max (ushort val1, ushort val2)
{
return (val1 > val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static byte Min (byte val1, byte val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static decimal Min (decimal val1, decimal val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static double Min (double val1, double val2)
{
if (Double.IsNaN (val1) || Double.IsNaN (val2)) {
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static float Min (float val1, float val2)
{
if (Single.IsNaN (val1) || Single.IsNaN (val2)) {
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static int Min (int val1, int val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static long Min (long val1, long val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static sbyte Min (sbyte val1, sbyte val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public static short Min (short val1, short val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static uint Min (uint val1, uint val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static ulong Min (ulong val1, ulong val2)
{
return (val1 < val2)? val1: val2;
}
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
[CLSCompliant (false)]
public static ushort Min (ushort val1, ushort val2)
{
public static decimal Round (decimal d, int decimals)
{
- if (decimals < 0 || decimals > 28)
- throw new ArgumentOutOfRangeException (Locale.GetText ("Value is too small or too big."));
+ return Decimal.Round (d, decimals);
+ }
- // Just call Decimal.Round(d, decimals); when it
- // rounds good.
- decimal p = (decimal) Math.Pow(10, decimals);
- decimal int_part = Decimal.Floor(d);
- decimal dec_part = d - int_part;
- dec_part *= 10000000000000000000000000000M;
- dec_part = Decimal.Floor(dec_part);
- dec_part /= (10000000000000000000000000000M / p);
- dec_part = Math.Round(dec_part);
- dec_part /= p;
- return int_part + dec_part;
+#if NET_2_0
+ [MonoTODO]
+ public static decimal Round (decimal d, MidpointRounding mode)
+ {
+ if ((mode != MidpointRounding.ToEven) && (mode != MidpointRounding.AwayFromZero))
+ throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
+
+ if (mode == MidpointRounding.ToEven)
+ return Round (d);
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public static decimal Round (decimal d, int decimals, MidpointRounding mode)
+ {
+ if ((mode != MidpointRounding.ToEven) && (mode != MidpointRounding.AwayFromZero))
+ throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
+
+ if (mode == MidpointRounding.ToEven)
+ return Round (d, decimals);
+ throw new NotImplementedException ();
}
+#endif
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static double Round (double d);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static double Round2 (double value, int digits);
+
+#if NET_2_0
+ public static double Round (double value, MidpointRounding mode)
+ {
+ if ((mode != MidpointRounding.ToEven) && (mode != MidpointRounding.AwayFromZero))
+ throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
+
+ if (mode == MidpointRounding.ToEven)
+ return Round (value);
+ if (value > 0)
+ return Floor (value + 0.5);
+ else
+ return Ceiling (value - 0.5);
+ }
+
+ [MonoTODO]
+ public static double Round (double value, int digits, MidpointRounding mode)
+ {
+ if ((mode != MidpointRounding.ToEven) && (mode != MidpointRounding.AwayFromZero))
+ throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
+
+ if (mode == MidpointRounding.ToEven)
+ return Round (value, digits);
+ throw new NotImplementedException ();
+ }
+#endif
+
public static int Sign (decimal value)
{
if (value > 0) return 1;
public extern static double Pow (double x, double y);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
+#if NET_2_0
+ [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
+#endif
public extern static double Sqrt (double x);
}
}