diff options
author | jfrijters <jfrijters> | 2011-01-11 08:16:48 +0300 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-01-11 08:16:48 +0300 |
commit | 8febdc94e9b7b49dd74929beda6df559d1a765ad (patch) | |
tree | 4a704ca145bf35e96a65442cef60b8690bee9989 /reflect/Util.cs | |
parent | 8b27b91cc36de186953c3b1d44cb36815132d8ed (diff) |
Fix for big endian systems. Thanks to Marek Safar for reporting this.
Diffstat (limited to 'reflect/Util.cs')
-rw-r--r-- | reflect/Util.cs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/reflect/Util.cs b/reflect/Util.cs index a471eedd..ca457d3e 100644 --- a/reflect/Util.cs +++ b/reflect/Util.cs @@ -1,5 +1,5 @@ /* - Copyright (C) 2008-2010 Jeroen Frijters + Copyright (C) 2008-2011 Jeroen Frijters This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -265,4 +265,27 @@ namespace IKVM.Reflection return h; } } + + [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)] + struct SingleConverter + { + [System.Runtime.InteropServices.FieldOffset(0)] + private int i; + [System.Runtime.InteropServices.FieldOffset(0)] + private float f; + + internal static int SingleToInt32Bits(float v) + { + SingleConverter c = new SingleConverter(); + c.f = v; + return c.i; + } + + internal static float Int32BitsToSingle(int v) + { + SingleConverter c = new SingleConverter(); + c.i = v; + return c.f; + } + } } |