Skip to content

Commit 7bef2ac

Browse files
committed
Fix cross-platform inconsistency in casting double.PositiveInfinity to int
When casting (int)double.PositiveInfinity, Windows returns -2147483648 (Int32.MinValue), while Unix-based systems return 2147483647 (Int32.MaxValue). This behavior leads to inconsistent results in calculations across platforms. An additional check has been added to standardize the behavior and ensure consistent results regardless of the operating system.
1 parent d5d3c47 commit 7bef2ac

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/OpenSilver.ControlsKit.Controls/StaggeredPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected override Size MeasureOverride(Size availableSize)
130130
double availableHeight = availableSize.Height - Padding.Top - Padding.Bottom;
131131

132132
_columnWidth = Math.Min(DesiredColumnWidth, availableWidth);
133-
int numColumns = Math.Max(1, (int)Math.Floor(availableWidth / _columnWidth));
133+
int numColumns = Math.Max(1, availableWidth == double.PositiveInfinity ? -1 : (int)Math.Floor(availableWidth / _columnWidth));
134134

135135
// adjust for column spacing on all columns expect the first
136136
double totalWidth = _columnWidth + ((numColumns - 1) * (_columnWidth + ColumnSpacing));

0 commit comments

Comments
 (0)