fn chunkspan_min2(a: f64, b: f64) -> f64 { if a < b { return a; } b } fn chunkspan_ceilpos(value: f64) -> f64 { let rest = value % 1.0; if rest > 0.0 { return value - rest + 1.0; } value } fn chunkspan_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn chunkspan_compute(size: f64, width: f64, index: f64) -> vector { let count = chunkspan_ceilpos(size / width); if index > count { return []; } let first = chunkspan_min2(size, index * width); [first, chunkspan_min2(size, first + width), count] } // Locate a fixed-width chunk including the final partial chunk. // Returns [start, exclusive end, chunk count]. Index equal to chunk count marks completion. pub fn chunkspan_bounds(size: f64, width: f64, index: f64) -> vector { if !(size >= 0.0 && size <= 9007199254740991.0 && size % 1.0 == 0.0) { return []; } if !(width >= 1.0 && width <= 9007199254740991.0 && width % 1.0 == 0.0) { return []; } if !(index >= 0.0 && index <= 9007199254740991.0 && index % 1.0 == 0.0) { return []; } let result = chunkspan_compute(size, width, index); if !chunkspan_finite(result) { return []; } result }