Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show negative numbers in Inspector #304

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ark_bls12_377::fr::Fr;
use ark_ff::{fields::Field, BigInteger, PrimeField};
use itertools::Itertools;
use num_bigint::{BigInt, Sign};
use num_bigint::{BigInt, BigUint, Sign};
use num_traits::{Euclid, FromPrimitive, Num, One, ToPrimitive, Zero};
use owo_colors::OwoColorize;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -451,8 +451,8 @@
fn pretty_with_base(&self, base: Base) -> String {
match self {
Value::BigInt(i) => match base {
Base::Dec => i.to_str_radix(10),
Base::Hex => format!("0x{}", i.to_str_radix(16)),
Base::Dec => to_negable_str(i, 10),
Base::Hex => format!("0x{}", to_negable_str(i, 16)),
Base::Bin | Base::Bool | Base::Loob => i.to_str_radix(2),
Base::Bytes => i
.to_bytes_be()
Expand Down Expand Up @@ -485,6 +485,23 @@
}
}
}

lazy_static::lazy_static! {
pub static ref TWO_128 : BigInt = BigInt::from_str_radix("1_0000_0000_0000_0000_0000_0000_0000_0000", 16).unwrap();
}

// Return a value which can be show as negative when its large enough.
fn to_negable_str(i: &BigInt, base: u32) -> String {
if i.cmp(&TWO_128).is_ge() {
let j: BigUint = Fr::MODULUS.into();
let k: BigInt = j.into();
let d: BigInt = -(k - i);
d.to_str_radix(base)
} else {
i.to_str_radix(base)
}
}

impl std::cmp::PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
Expand Down Expand Up @@ -1158,7 +1175,7 @@
pub fn iter_module<'a>(
&'a self,
module: &'a str,
) -> impl Iterator<Item = (ColumnRef, &Column)> + 'a {

Check warning on line 1178 in src/column.rs

View workflow job for this annotation

GitHub Actions / build

elided lifetime has a name
self.iter().filter(move |c| c.1.handle.module == module)
}

Expand Down
Loading