[READ-ONLY] Mirror of https://github.com/probablykasper/cpc. Text calculator with support for units and conversion cpc.kasper.space
calculator cli conversion converter library math package units units-converter wasm website
0

Configure Feed

Select the types of activity you want to include in your feed.

Add modulo

Kasper (Jun 24, 2026, 8:54 AM +0200) a27ba4ed 9fe708e1

+9 -11
+9 -11
src/units.rs
··· 758 758 /// 759 759 /// Temperatures don't work. 760 760 pub fn modulo(left: Number, right: Number) -> Result<Number, String> { 761 - todo!(); 762 - // if left.unit.category() == Temperature || right.unit.category() == Temperature { 763 - // // if temperature 764 - // Err(format!("Cannot modulo {:?} by {:?}", left.unit, right.unit)) 765 - // } else if left.unit.category() == right.unit.category() { 766 - // // 5 km % 3 m 767 - // let (left, right) = convert_to_lowest(left, right)?; 768 - // Ok(Number::new(left.value % right.value, left.unit)) 769 - // } else { 770 - // Err(format!("Cannot modulo {:?} by {:?}", left.unit, right.unit)) 771 - // } 761 + if left.contains_primitive(Temperature) || right.contains_primitive(Temperature) { 762 + Err(format!("Cannot modulo {:?} by {:?}", left.unit, right.unit)) 763 + } else if left.primitive_unit() == right.primitive_unit() { 764 + // 5 km % 3 m 765 + let (left, right) = convert_to_lowest(left, right)?; 766 + Ok(Number::with_unit(left.value % right.value, left.unit)) 767 + } else { 768 + Err(format!("Cannot modulo {:?} by {:?}", left.unit, right.unit)) 769 + } 772 770 } 773 771 774 772 /// Returns a [`Number`] to the power of another [`Number`]