Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ private static uint ScaleToUint(float v)

private static float ScaleToFloat(uint v)
{
float unscaled = v * Maximum / IntScale;

if (unscaled > Maximum)
unscaled -= Maximum * 2;
return unscaled;
// Values above IntScale are two's-complement negatives produced by ScaleToUint's mask.
int signed = v > IntScale ? (int)v - (IntMask + 1) : (int)v;
return signed * Maximum / IntScale;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,16 @@ private static ulong ScaleToUint_L(float v)

private static float ScaleToFloat_H(ulong v)
{
float unscaled = v * Maximum / IntScale_H;

if (unscaled > Maximum)
unscaled -= Maximum * 2;
return unscaled;
// Values above IntScale are two's-complement negatives produced by ScaleToUint's mask.
long signed = v > IntScale_H ? (long)v - (IntMask_H + 1) : (long)v;
return signed * Maximum / IntScale_H;
}

private static float ScaleToFloat_L(ulong v)
{
float unscaled = v * Maximum / IntScale_L;

if (unscaled > Maximum)
unscaled -= Maximum * 2;
return unscaled;
// Values above IntScale are two's-complement negatives produced by ScaleToUint's mask.
long signed = v > IntScale_L ? (long)v - (IntMask_L + 1) : (long)v;
return signed * Maximum / IntScale_L;
}

public static Quaternion Decompress(ulong compressed)
Expand Down