Author: miguel
Date: 2007-03-16 14:55:21 -0500 (Fri, 16 Mar 2007)
New Revision: 74485
Modified:
trunk/mcs/class/corlib/System/BitConverter.cs
trunk/mcs/class/corlib/System/ChangeLog
trunk/mcs/class/corlib/System/Math.cs
Log:
2007-03-16 Miguel de Icaza <[EMAIL PROTECTED]>
* BitConverter.cs: Revert the patch from 72237 as that introduces
a regression and we are not sure yet what we will be doing about
that.
Introduce a new InternalInt64BitsToDouble method that provides the
fixed functionality, mark it as internal.
Introduce a new SwappableToDouble method that includes the
swapping ToDouble routine as introduced by Zoltan on 72237, this
is used by InternalInt64BitsToDouble.
* Math.cs (IEEERemainder): Use the InternalInt64BitsToDouble
routine here to preserve the semantics from Zoltan.
The problem with BitConverter.cs is that it is completely hossed.
In .NET 1.1 it is a bitwise copy, no attempt is ever done to do
endian-specific swapping. In .NET 2.0 it is *almost* like that,
but it is subtly broken: if data is unaligned then endian
conversions happen. If the data is properly aligned it behaves
like 1.0.
In general BitConverter is a sad class that offers little control,
we will be introducing a new mono bit converter and encourage
users to use that instead of the entirely broken
System.BitConverter.
Modified: trunk/mcs/class/corlib/System/BitConverter.cs
===================================================================
--- trunk/mcs/class/corlib/System/BitConverter.cs 2007-03-16 19:55:00 UTC
(rev 74484)
+++ trunk/mcs/class/corlib/System/BitConverter.cs 2007-03-16 19:55:21 UTC
(rev 74485)
@@ -81,6 +81,11 @@
return ToDouble (GetBytes (value), 0);
}
+ internal static double InternalInt64BitsToDouble (long value)
+ {
+ return SwappableToDouble (GetBytes (value), 0);
+ }
+
unsafe static byte[] GetBytes (byte *ptr, int count)
{
byte [] ret = new byte [count];
@@ -301,6 +306,40 @@
return ret;
}
+
+ PutBytes ((byte *) &ret, value, startIndex, 8);
+
+ return ret;
+ }
+
+ unsafe internal static double SwappableToDouble (byte[] value,
int startIndex)
+ {
+ double ret;
+
+ if (SwappedWordsInDouble) {
+ byte* p = (byte*)&ret;
+ if (value == null)
+ throw new ArgumentNullException
("value");
+
+ if (startIndex < 0)
+ throw new ArgumentOutOfRangeException
("startIndex < 0");
+
+ // avoid integer overflow (with large pos/neg
start_index values)
+ if (value.Length - 8 < startIndex) {
+ throw new ArgumentOutOfRangeException
(Locale.GetText (
+ "Value is too big to return the
requested type."), "startIndex");
+ }
+ p [0] = value [startIndex + 4];
+ p [1] = value [startIndex + 5];
+ p [2] = value [startIndex + 6];
+ p [3] = value [startIndex + 7];
+ p [4] = value [startIndex + 0];
+ p [5] = value [startIndex + 1];
+ p [6] = value [startIndex + 2];
+ p [7] = value [startIndex + 3];
+
+ return ret;
+ }
else if (!IsLittleEndian) {
byte* p = (byte*)&ret;
if (value == null)
@@ -330,7 +369,7 @@
return ret;
}
-
+
public static string ToString (byte[] value)
{
if (value == null) {
Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog 2007-03-16 19:55:00 UTC (rev
74484)
+++ trunk/mcs/class/corlib/System/ChangeLog 2007-03-16 19:55:21 UTC (rev
74485)
@@ -1,3 +1,31 @@
+2007-03-16 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * BitConverter.cs: Revert the patch from 72237 as that introduces
+ a regression and we are not sure yet what we will be doing about
+ that.
+
+ Introduce a new InternalInt64BitsToDouble method that provides the
+ fixed functionality, mark it as internal.
+
+ Introduce a new SwappableToDouble method that includes the
+ swapping ToDouble routine as introduced by Zoltan on 72237, this
+ is used by InternalInt64BitsToDouble.
+
+ * Math.cs (IEEERemainder): Use the InternalInt64BitsToDouble
+ routine here to preserve the semantics from Zoltan.
+
+ The problem with BitConverter.cs is that it is completely hossed.
+ In .NET 1.1 it is a bitwise copy, no attempt is ever done to do
+ endian-specific swapping. In .NET 2.0 it is *almost* like that,
+ but it is subtly broken: if data is unaligned then endian
+ conversions happen. If the data is properly aligned it behaves
+ like 1.0.
+
+ In general BitConverter is a sad class that offers little control,
+ we will be introducing a new mono bit converter and encourage
+ users to use that instead of the entirely broken
+ System.BitConverter.
+
2007-03-11 Gert Driesen <[EMAIL PROTECTED]>
* Delegate.cs: Fixed bootstrap build.
Modified: trunk/mcs/class/corlib/System/Math.cs
===================================================================
--- trunk/mcs/class/corlib/System/Math.cs 2007-03-16 19:55:00 UTC (rev
74484)
+++ trunk/mcs/class/corlib/System/Math.cs 2007-03-16 19:55:21 UTC (rev
74485)
@@ -145,7 +145,7 @@
r = x - (y * Math.Round(x/y));
if (r != 0)
return r;
- return (x > 0) ? 0: (BitConverter.Int64BitsToDouble
(Int64.MinValue));
+ return (x > 0) ? 0:
(BitConverter.InternalInt64BitsToDouble (Int64.MinValue));
}
public static double Log (double a, double newBase)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches