libdgf/LibDgf/Ps2/Vif/VuFloat.cs
2021-03-17 03:18:15 -06:00

33 lines
860 B
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace LibDgf.Ps2.Vif
{
public struct VuFloat
{
public uint Packed;
public static implicit operator double(VuFloat f)
{
ulong sign = (f.Packed >> 31) & 1;
ulong exponent = (f.Packed >> 23) & 0xff;
ulong mantissa = f.Packed & 0x7fffff;
ulong doubleValue;
if (exponent == 0)
{
doubleValue = sign << 63;
}
else
{
doubleValue = (sign << 63) | ((exponent + 1023 - 127) << 52) | (mantissa << 29);
}
return BitConverter.ToDouble(BitConverter.GetBytes(doubleValue), 0);
}
public override string ToString()
{
return ((double)this).ToString();
}
}
}