mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 08:13:11 +00:00
fix subtraction
This commit is contained in:
parent
c464c038af
commit
20dae028d8
@ -268,7 +268,7 @@ impl Sub for CrandallField {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[allow(clippy::suspicious_arithmetic_impl)]
|
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||||
fn sub(self, rhs: Self) -> Self {
|
fn sub(self, rhs: Self) -> Self {
|
||||||
let (diff, under) = self.0.overflowing_sub(rhs.0);
|
let (diff, under) = self.0.overflowing_sub(rhs.to_canonical_u64());
|
||||||
Self(diff.overflowing_add((under as u64) * Self::ORDER).0)
|
Self(diff.overflowing_add((under as u64) * Self::ORDER).0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -305,6 +305,16 @@ macro_rules! test_arithmetic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn subtraction() {
|
||||||
|
type F = $field;
|
||||||
|
|
||||||
|
let (a, b) = (F::from_canonical_u64((F::ORDER + 1) / 2), F::TWO);
|
||||||
|
let x = a * b;
|
||||||
|
assert_eq!(x, F::ONE);
|
||||||
|
assert_eq!(F::ZERO - x, F::NEG_ONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user