chiark / gitweb /
Trivially implement subtraction.
authorSimon Tatham <anakin@pobox.com>
Fri, 11 Apr 2025 18:24:31 +0000 (19:24 +0100)
committerSimon Tatham <anakin@pobox.com>
Fri, 11 Apr 2025 18:24:31 +0000 (19:24 +0100)
src/finitenimber.rs

index 5ea19dae8a91eeab3fd5f37eaf38ee5fbdf257fa..7805ed50c1dd2b18a61ba9959278a9addc652749 100644 (file)
@@ -1,6 +1,6 @@
 use core::cmp::max;
 use core::fmt::{Debug, Formatter};
-use core::ops::{Add, Mul};
+use core::ops::{Add, Sub, Mul};
 
 type Word = u64; // element type of the vectors we use
 const WORDLEVELS: usize = 6; // 2^{2^6} = 64 = size of Word
@@ -269,6 +269,11 @@ impl<'a, 'b> Add<FiniteNimberRef<'a>> for FiniteNimberRef<'b> {
     }
 }
 
+impl<'a, 'b> Sub<FiniteNimberRef<'a>> for FiniteNimberRef<'b> {
+    type Output = FiniteNimber;
+    fn sub(self, other: FiniteNimberRef<'a>) -> FiniteNimber { self + other }
+}
+
 impl<'a> FiniteNimberRef<'a> {
     fn mul_by_h(self, level: usize) -> FiniteNimber {
         match level.checked_sub(1) {
@@ -314,6 +319,7 @@ impl<'a, 'b> Mul<FiniteNimberRef<'a>> for FiniteNimberRef<'b> {
 }
 
 impl_binop_wrappers!(Add, add);
+impl_binop_wrappers!(Sub, sub);
 impl_binop_wrappers!(Mul, mul);
 
 #[cfg(test)]