Hi, I have sent a patch for Math.cs. Here I have a newer patch for this stuff. I returned to the original version of Math.cs, now the diff is more undestandable.
The files are: mcs/class/corlib/System/Math.cs mono/mono/metadata/icall.c mono/mono/metadata/sysmath.h mono/mono/metadata/sysmath.c Sorry for the confusion but I were awake all the night and I falled in a collapse. I promise that I will be working in Math.cs to get the best fit with MS.NET Math. See you, Pedro -- Pedro Martinez Juliá \ [EMAIL PROTECTED] )| [EMAIL PROTECTED] / http://yoros.cjb.net Socio HispaLinux #311 Usuario Linux #275438 - http://counter.li.org GnuPG public information: pub 1024D/74F1D3AC Key fingerprint = 8431 7B47 D2B4 5A46 5F8E 534F 588B E285 74F1 D3AC
Index: Math.cs =================================================================== RCS file: /mono/mcs/class/corlib/System/Math.cs,v retrieving revision 1.15 diff -u -p -r1.15 Math.cs --- Math.cs 24 Jan 2003 16:10:01 -0000 1.15 +++ Math.cs 1 Feb 2003 21:45:20 -0000 @@ -4,8 +4,10 @@ // Author: // Bob Smith ([EMAIL PROTECTED]) // Dan Lewis ([EMAIL PROTECTED]) +// Pedro Martínez Juliá ([EMAIL PROTECTED]) // // (C) 2001 Bob Smith. http://www.thestuff.net +// Copyright (C) 2003 Pedro Martínez Juliá <[EMAIL PROTECTED]> // using System; @@ -62,37 +64,16 @@ namespace System public static double Ceiling(double a) { - if (Double.IsNaN(a)){ - return Double.NaN; - } - - if (Double.IsNegativeInfinity(a)){ - return Double.NegativeInfinity; - } - - if (Double.IsPositiveInfinity(a)){ - return Double.PositiveInfinity; - } - - double b = (double)((long)a); - return (b < a)? b+1: b; - } - public static double Floor(double d) { - if (Double.IsNaN(d)){ - return Double.NaN; - } - - if (Double.IsNegativeInfinity(d)){ - return Double.NegativeInfinity; - } - - if (Double.IsPositiveInfinity(d)){ - return Double.PositiveInfinity; - } - - double b = (double)((long)d); - return (d < 0 && d != b) ? --b : b; + double result = Floor(value); + if (result != value) { + result++; + } + return result; } + + [MethodImplAttribute (MethodImplOptions.InternalCall)] + public extern static double Floor (double value); + public static double IEEERemainder(double x, double y) { double r; @@ -215,44 +196,16 @@ namespace System public static decimal Round(decimal d) { - decimal r = (decimal)((long)d); - decimal a = Abs (d - r); - if (a > .5M) return (r >= 0 ? ++r : --r); - else if (a <.5M) return r; - else - { - if (r%2 == 0) return r; - else return ++r; - } + return Decimal.Round(result, 0); } public static decimal Round(decimal d, int decimals) { - long p = 1; - int c; - decimal retval = d; - if (decimals < 0 || decimals > 15) - throw new ArgumentOutOfRangeException(Locale.GetText ( - "Value is too small or too big.")); - else if (decimals == 0) - return Math.Round(d); - for (c=0; c<decimals; c++) p*=10; - retval*=p; - retval=Math.Round(retval); - retval/=p; - return retval; - } - public static double Round(double d) - { - double r = (double)((long)d); - double a = Abs (d - r); - if (a > .5) return (r >= 0 ? ++r : --r); - else if (a <.5) return r; - else - { - if (r%2 == 0) return r; - else return ++r; - } + return Decimal.Round(result, decimals); } + + [MethodImplAttribute (MethodImplOptions.InternalCall)] + public static double Round(double d); + public static double Round(double value, int digits) { long p = 1; int c; @@ -262,7 +215,7 @@ namespace System "Value is too small or too big.")); else if (digits == 0) return Math.Round(value); - for (c=0; c<digits; c++) p*=10; + p = Math.Pow(10, digits); retval*=p; retval=Math.Round(retval); retval/=p; @@ -275,11 +228,15 @@ namespace System } public static int Sign(double value) { + if (Double.IsNaN(value)) + throw new ArithmeticException("NAN"); if (value > 0) return 1; return (value == 0)? 0: -1; } public static int Sign(float value) { + if (Single.IsNaN(value)) + throw new ArithmeticException("NAN"); if (value > 0) return 1; return (value == 0)? 0: -1; }
Index: icall.c =================================================================== RCS file: /mono/mono/mono/metadata/icall.c,v retrieving revision 1.256 diff -u -p -r1.256 icall.c --- icall.c 31 Jan 2003 18:38:14 -0000 1.256 +++ icall.c 1 Feb 2003 21:30:00 -0000 @@ -3552,6 +3552,8 @@ static gconstpointer icall_map [] = { /* * System.Math */ + "System.Math::Floor", ves_icall_System_Math_Floor, + "System.Math::Round", ves_icall_System_Math_Round, "System.Math::Sin", ves_icall_System_Math_Sin, "System.Math::Cos", ves_icall_System_Math_Cos, "System.Math::Tan", ves_icall_System_Math_Tan,
Index: sysmath.h =================================================================== RCS file: /mono/mono/mono/metadata/sysmath.h,v retrieving revision 1.1 diff -u -p -r1.1 sysmath.h --- sysmath.h 18 Mar 2002 16:49:45 -0000 1.1 +++ sysmath.h 1 Feb 2003 21:30:21 -0000 @@ -13,6 +13,9 @@ #include <config.h> #include <glib.h> +extern gdouble ves_icall_System_Math_Floor (gdouble x); +extern gdouble ves_icall_System_Math_Round (gdouble x); + extern gdouble ves_icall_System_Math_Sin (gdouble x);
Index: sysmath.c =================================================================== RCS file: /mono/mono/mono/metadata/sysmath.c,v retrieving revision 1.7 diff -u -p -r1.7 sysmath.c --- sysmath.c 28 Nov 2002 10:02:07 -0000 1.7 +++ sysmath.c 1 Feb 2003 21:30:30 -0000 @@ -29,6 +29,16 @@ static __huge_val_t __huge_val = { __HUG # define HUGE_VAL (__huge_val.__d) #endif +gdouble ves_icall_System_Math_Floor (gdouble x) { + MONO_ARCH_SAVE_REGS; + return floor(x); +} + +gdouble ves_icall_System_Math_Round (gdouble x) { + MONO_ARCH_SAVE_REGS; + return round(x); +} + gdouble ves_icall_System_Math_Sin (gdouble x) {