Hi, I have a great, great problem with the last Math.cs I sent, forget it, please. Please get this one.
Thank you, and sorry, again. 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 2 Feb 2003 00:25:24 -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(a); + if (result != a) { + 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(d, 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(d, decimals); } + + [MethodImplAttribute (MethodImplOptions.InternalCall)] + public extern 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 = (long) 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; }