implemented unpacking of HalfSingle
This commit is contained in:
parent
77063af953
commit
c60d9405dd
@ -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)
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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" />
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user