mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [stream] avoid overflowing range arithmetic (#393)
This commit is contained in:
1 parent
6ff2966d50
commit
8225b6d7d9
2 files changed
+21
-5
No files matched your search
+8
-5
@@ -101,11 +101,14 @@ func FromRange[T constraints.Integer | constraints.Float](start, end, step T) St
|
||||
panic("stream.FromRange: param step should be positive")
|
||||
}
|
||||
|
||||
l := int((end-start)/step) + 1
|
||||
source := make([]T, l)
|
||||
|
||||
for i := 0; i < l; i++ {
|
||||
source[i] = start + (T(i) * step)
|
||||
source := make([]T, 0)
|
||||
for value := start; value <= end; {
|
||||
source = append(source, value)
|
||||
next := value + step
|
||||
if next <= value {
|
||||
break
|
||||
}
|
||||
value = next
|
||||
}
|
||||
|
||||
return FromSlice(source)
|
||||
|
||||
Reference in new issue
Block a user