fn lineamount_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 lineamount_counts(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= 0.0 && value <= 9007199254740991.0 && value % 1.0 == 0.0) { return false; } i += 1; } true } fn lineamount_compute(units: vector, prices: vector) -> vector { if len(units) != len(prices) { return []; } let mut total = 0.0; let mut lines = 0; let mut i = 0; while i < len(units) { let q = at(units, i); let price = at(prices, i); if q > 0.0 && price > (9007199254740991.0 - total) / q { return []; } total += q * price; if q > 0.0 { lines += 1; } i += 1; } [total, lines] } // Extend paired invoice quantities and prices in integer minor units. // Returns [subtotal, nonzero lines]. Rejects unmatched columns and totals beyond exact integer representation. pub fn lineamount_subtotal(units: vector, prices: vector) -> vector { if !lineamount_counts(units) { return []; } if !lineamount_counts(prices) { return []; } let result = lineamount_compute(units, prices); if !lineamount_finite(result) { return []; } result }