2016-06-19 21:43:09 +00:00
|
|
|
#include "Types.h"
|
|
|
|
#include "R3DFloat.h"
|
2022-10-01 01:44:22 +00:00
|
|
|
#include "Util/BitCast.h"
|
2016-06-19 21:43:09 +00:00
|
|
|
|
|
|
|
float R3DFloat::GetFloat16(UINT16 f)
|
|
|
|
{
|
|
|
|
return ToFloat(Convert16BitProFloat(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
float R3DFloat::GetFloat32(UINT32 f)
|
|
|
|
{
|
|
|
|
return ToFloat(ConvertProFloat(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 R3DFloat::ConvertProFloat(UINT32 a1)
|
|
|
|
{
|
2022-08-19 19:34:22 +00:00
|
|
|
UINT32 exponent = (a1 & 0x7E000000) >> 25;
|
2016-06-19 21:43:09 +00:00
|
|
|
|
|
|
|
if (exponent <= 31) { // positive
|
|
|
|
exponent += 127;
|
|
|
|
}
|
|
|
|
else { // negative exponent
|
2022-08-19 19:34:22 +00:00
|
|
|
exponent += 127 - 64;
|
2016-06-19 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-19 19:34:22 +00:00
|
|
|
UINT32 mantissa = (a1 & 0x1FFFFFF) >> 2;
|
2016-06-19 21:43:09 +00:00
|
|
|
|
|
|
|
return (a1 & 0x80000000) | (exponent << 23) | mantissa;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 R3DFloat::Convert16BitProFloat(UINT32 a1)
|
|
|
|
{
|
|
|
|
return ConvertProFloat(a1 << 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
float R3DFloat::ToFloat(UINT32 a1)
|
|
|
|
{
|
2022-10-01 01:44:22 +00:00
|
|
|
return Util::UintAsFloat(a1);
|
2022-08-19 19:34:22 +00:00
|
|
|
}
|