openvm_instructions/
utils.rs
1use num_bigint::BigUint;
2use num_traits::Num;
3use openvm_stark_backend::p3_field::Field;
4
5pub fn parse_biguint_auto(s: &str) -> Option<BigUint> {
6 let s = s.trim();
7 if s.starts_with("0x") || s.starts_with("0X") {
8 BigUint::from_str_radix(&s[2..], 16).ok()
9 } else if s.starts_with("0b") || s.starts_with("0B") {
10 BigUint::from_str_radix(&s[2..], 2).ok()
11 } else {
12 BigUint::from_str_radix(s, 10).ok()
13 }
14}
15
16pub fn isize_to_field<F: Field>(value: isize) -> F {
17 if value < 0 {
18 return F::NEG_ONE * F::from_canonical_usize(value.unsigned_abs());
19 }
20 F::from_canonical_usize(value as usize)
21}