[Mono-dev] Patch for Math.cs

Felipe Almeida Lessa felipe.lessa at gmail.com
Sun Mar 4 20:09:14 EST 2007


I'm not a Mono dev so I may be wrong, but see my two comments below.

On 3/4/07, Dennis Hayes <denisraytek at yahoo.com> wrote:
> @@ -411,26 +411,25 @@
>  #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);
> +
> +                       throw new ArgumentException ("The value '" + mode +
> "' is not valid for this usage of the type MidpointRounding.", "mode");
>                 }


Is it just me or this throw is non-reachable? The if clause just
before it should catch every possible paths (that could lead to it).



>                 [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)
> +            if (mode == MidpointRounding.ToEven)
>                                 return Round (value, digits);
> -                       throw new NotImplementedException ();
> +                       if (mode == MidpointRounding.ToEven)
> +                           throw new NotImplementedException ();
> +
> +                       throw new ArgumentException ("The value '" + mode +
> "' is not valid for this usage of the type MidpointRounding.", "mode");
>                 }


Two checks to MidpointRounding.ToEven? The second one is unreachable
as well (although I don't know if the compiler is clever enough to
discover that). I suppose you meant MidpointRounding.AwayFromZero on
the second if.


HTH,

-- 
Felipe.



More information about the Mono-devel-list mailing list