[Mono-dev] Patch for Math.cs

Dennis Hayes denisraytek at yahoo.com
Fri Mar 9 20:25:57 EST 2007


I am working on updated test and patch.
  I expect to have them done tonight or tommorrow.
  I will add the internationalization fix also.
  Dennis
  

Miguel de Icaza <miguel at novell.com> wrote:
  Hello,

The patch should use:

throw new ArgumentException (Locale.GetText ("...."))

So that this can be later internationalized.

Can someone send me the updated patch?

> Just out of interest, could you check the performance of the method if
> you change code patterns like:
> 
> if (value > 0)
> return Floor (value + 0.5);
> else
> return Ceiling (value - 0.5);
> 
> to:
> 
> return (value > 0) ? Floor(value+0.5) : Ceiling(value - 0.5);
> 
> When i was profiling stuff before i think there was a performance
> boost when using the turnary form, I may be wrong though. If it does
> turn out to be faster, you could make that change to. If it isn't, no
> worries. 
> 
> Alan.
> 
> 
> On 3/4/07, Dennis Hayes wrote:
> This is a minor clean up of Math.cs.
> Basicly, in the methods that use MidpointRounding Mode, it
> moves the check for a valid mode to the end of the method.
> 
> Since the mode is checked in the method, doing this eliminates
> the extra check. Also, the check should never fail, since an
> enum is being passed in. This will make the code a little
> faster.
> 
> I don't have svn access setup, so I need someone to check this
> in also.
> 
> I did not include any tests, because this should not
> have added or modifyed anything testable.
> 
> Should I do anything elseor do anything differently?
> Would this be better as a switch?
> Thanks,
> Dennis
> 
> ______________________________________________________________
> Need a quick answer? Get one in minutes from people who know.
> Ask your question on Yahoo! Answers.
> --0-164504892-1173052624=:24413--
> 
> 
> Index: Math.cs
> ===================================================================
> --- Math.cs (revision 73696)
> +++ Math.cs (working copy)
> @@ -373,27 +373,27 @@ 
> [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
> 
> - [MethodImplAttribute
> (MethodImplOptions.InternalCall)]
> + [MethodImplAttribute
> (MethodImplOptions.InternalCall)]
> public extern static double Round (double d); 
> 
> public static double Round (double value, int
> digits)
> @@ -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"); 
> }
> 
> [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"); 
> }
> 
> public static double Truncate (double d)
> @@ -454,7 +453,7 @@
> }
> #endif
> 
> - public static int Sign (decimal value)
> + public static int Sign (decimal value) 
> {
> if (value > 0) return 1;
> return (value == 0)? 0: -1;
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list


 
---------------------------------
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070309/951247ac/attachment.html 


More information about the Mono-devel-list mailing list