mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(mathutil): stop stepped ranges when values stop increasing (#376)
This commit is contained in:
1 parent
b40eea78c3
commit
b282ada39e
2 files changed
+11
-2
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user