[Mono-dev] Math.cs patch correction
Sebastien Pouliot
sebastien.pouliot at gmail.com
Mon Mar 5 08:15:00 EST 2007
Hello Dennis,
Considering the first patch wasn't totally correct (in one case) it's
clear that the existing unit tests are complete enough. So please check
them and complete them to ensure all cases (including an invalid enum
value) are tested.
Thanks!
On Sun, 2007-03-04 at 19:45 -0800, Dennis Hayes wrote:
> This again cleans up the 2.0 rounding methods that use the
> MidpointRounding enum options.
>
> It will give a small speed increase by moving a test that should never
> fail from the top of the method to the bottom of the method, where is
> should never need to be executed.
>
> My next task is to implment the missing methods.
> Do I need to do anything more or different?
> Dennis
>
>
>
>
> ______________________________________________________________________
> Finding fabulous fares is fun.
> Let Yahoo! FareChase search your favorite travel sites to find flight
> and hotel bargains.
> plain text document attachment (math.diff), "pat780224508"
> Index: Math.cs
> ===================================================================
> --- Math.cs (revision 73696)
> +++ Math.cs (working copy)
> @@ -1,4 +1,4 @@
> -//
> +//
> // System.Math.cs
> //
> // Authors:
> @@ -373,23 +373,23 @@
> [MonoTODO ("Not implemented")]
> 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 ();
> + if (mode == MidpointRounding.AwayFromZero)
> + throw new NotImplementedException ();
> +
> + throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
> }
>
> [MonoTODO ("Not implemented")]
> 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 ();
> + if (mode == MidpointRounding.AwayFromZero)
> + throw new NotImplementedException ();
> +
> + throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
> }
> #endif
>
> @@ -411,26 +411,26 @@
> #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);
> + if (mode == MidpointRounding.AwayFromZero){
> + if (value > 0)
> + return Floor (value + 0.5);
> + else
> + return Ceiling (value - 0.5);
> + }
> + throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
> }
>
> [MonoTODO ("Not implemented")]
> 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 ();
> + if (mode == MidpointRounding.AwayFromZero)
> + throw new NotImplementedException ();
> +
> + throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
> }
>
> public static double Truncate (double d)
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
--
Sebastien Pouliot <sebastien at ximian.com>
Blog: http://pages.infinit.net/ctech/
More information about the Mono-devel-list
mailing list