// Derive the EAN-13 check digit from exactly twelve decimal data digits. Invalid input returns minus one. pub fn ean13_digit(digits: vector) -> f64 { if len(digits)!=12 { return -1.0; } let mut i = 0; let mut sum = 0.0; while i<12 { let d = at(digits,i); if d<0.0 || d>9.0 || d%1.0 != 0.0 { return -1.0; } let weight = if i%2 == 0 { 1.0 } else { 3.0 }; sum += weight*d; i += 1; } (10.0-sum%10.0)%10.0 }