fix(mathutil): stop stepped ranges when values stop increasing (#376)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-23 18:04:43 +08:00
1 parent b40eea78c3
commit b282ada39e
2 files changed
+11 -2

No files matched your search

+7 -2
View File
@@ -270,12 +270,17 @@ func Range[T constraints.Integer | constraints.Float](start T, count int) []T {
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T {
result := []T{}
if start >= end || step == 0 {
if start >= end || step <= 0 {
return result
}
for i := start; i < end; i += step {
for i := start; i < end; {
result = append(result, i)
next := i + step
if next <= i {
break
}
i = next
}
return result