implemented unpacking of HalfSingle

This commit is contained in:
Glatzemann 2011-11-08 14:02:04 +00:00
parent 77063af953
commit c60d9405dd
4 changed files with 50 additions and 3 deletions

View File

@ -160,6 +160,18 @@ namespace ANX.Framework.TestCenter
}
}
public static void ConvertEquals(float a, float b, String test)
{
if (a.Equals(b))
{
Assert.Pass(test + " passed");
}
else
{
Assert.Fail(String.Format("{0} failed: float a: ({1}) float b: ({2})", test, a, b));
}
}
public static void ConvertEquals(byte a, byte b, String test)
{
if (a == b)

View File

@ -88,5 +88,13 @@ namespace ANX.Framework.TestCenter.Strukturen.PackedVector
AssertHelper.ConvertEquals(xnaVal, anxVal, "Constructor1");
}
[Test, TestCaseSource("floats")]
public void unpack1(float single)
{
XNAHalfSingle xnaVal = new XNAHalfSingle(single);
ANXHalfSingle anxVal = new ANXHalfSingle(single);
AssertHelper.ConvertEquals(xnaVal.ToSingle(), anxVal.ToSingle(), "unpack1");
}
}
}

View File

@ -24,6 +24,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -32,6 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

View File

@ -125,10 +125,35 @@ namespace ANX.Framework.Graphics.PackedVector
}
}
internal static float convert(UInt16 value)
internal static unsafe float convert(ushort value)
{
//TODO: implement
throw new NotImplementedException();
uint rst;
uint mantissa = (uint)(value & 1023);
uint exp = 0xfffffff2;
if ((value & -33792) == 0)
{
if (mantissa != 0)
{
while ((mantissa & 1024) == 0)
{
exp--;
mantissa = mantissa << 1;
}
mantissa &= 0xfffffbff;
rst = ((uint)(((value & 0x8000) << 16) | ((exp + 127) << 23))) | (mantissa << 13);
}
else
{
rst = (uint)((value & 0x8000) << 16);
}
}
else
{
rst = (uint)((((value & 0x8000) << 16) | (((((value >> 10) & 0x1f) - 15) + 127) << 23)) | (mantissa << 13));
}
return *(((float*)&rst));
}
}
}