Skip to content

Commit cb36494

Browse files
committed
fix: over-rounding on negative midpoint values
1 parent 5bab7bc commit cb36494

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/FixedMathSharp/Core/FixedMath.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static Fixed64 Round(Fixed64 value, MidpointRounding mode = MidpointRound
176176
// When value is exactly Fixed64.Halfway between two numbers
177177
return mode switch
178178
{
179-
MidpointRounding.AwayFromZero => value.m_rawValue > 0 ? integralPart + Fixed64.One : integralPart - Fixed64.One,// If it's exactly Fixed64.Halfway, round away from Fixed64.Zero
179+
MidpointRounding.AwayFromZero => value.m_rawValue > 0 ? integralPart + Fixed64.One : integralPart,// For negative midpoints, Floor() is already away from zero
180180
_ => (integralPart.m_rawValue & ONE_L) == 0 ? integralPart : integralPart + Fixed64.One,// Rounds to the nearest even number (default behavior)
181181
};
182182
}
@@ -366,4 +366,4 @@ public static long AddOverflowHelper(long x, long y, ref bool overflow)
366366

367367
#endregion
368368
}
369-
}
369+
}

0 commit comments

Comments
 (0)