Skip to content

Commit

Permalink
fix i64 (#2202)
Browse files Browse the repository at this point in the history
Copied from the GL impl
  • Loading branch information
leonardoalt authored Dec 6, 2024
1 parent 9560cc8 commit b1bdec5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion number/src/plonky3_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@ macro_rules! powdr_field_plonky3 {

impl From<i64> for $name {
fn from(n: i64) -> Self {
From::<u64>::from(n as u64)
Self::from(if n < 0 {
// If n < 0, then this is guaranteed to overflow since
// both arguments have their high bit set, so the result
// is in the canonical range.
Self::modulus()
.try_into_u64()
.unwrap()
.wrapping_add(n as u64)
} else {
n as u64
})
}
}

Expand Down

0 comments on commit b1bdec5

Please sign in to comment.