pub fn nat_to_limbs<'a, F: PrimeField>(
    nat: &Integer,
    limb_width: usize,
    n_limbs: usize,
) -> Result<Vec<F>, SynthesisError> {
    let mask = int_with_n_ones(limb_width);
    let mut nat = nat.clone();
    if nat.significant_bits() as usize <= n_limbs * limb_width {
        Ok((0..n_limbs)
            .map(|_| {
                let r = Integer::from(&nat & &mask);
                nat >>= limb_width as u32;
                nat_to_f(&r).unwrap()
            })
            .collect())
    } else {
        eprintln!(
            "nat {} does not fit in {} limbs of width {}",
            nat, n_limbs, limb_width
        );
        Err(SynthesisError::Unsatisfiable)
    }
}
/// Compute the limbs encoding a natural number.
/// The limbs are assumed to be based the `limb_width` power of 2.
Compute the limbs encoding a natural number.
The limbs are assumed to be based the `limb_width` power of 2.
Compute the limbs encoding a natural number . The limbs are assumed to be based the ` limb_width ` power of 2 .
pub fn nat_to_limbs<'a, F: PrimeField>(
    nat: &Integer,
    limb_width: usize,
    n_limbs: usize,
) -> Result<Vec<F>, SynthesisError> {
    let mask = int_with_n_ones(limb_width);
    let mut nat = nat.clone();
    if nat.significant_bits() as usize <= n_limbs * limb_width {
        Ok((0..n_limbs)
            .map(|_| {
                let r = Integer::from(&nat & &mask);
                nat >>= limb_width as u32;
                nat_to_f(&r).unwrap()
            })
            .collect())
    } else {
        eprintln!(
            "nat {} does not fit in {} limbs of width {}",
            nat, n_limbs, limb_width
        );
        Err(SynthesisError::Unsatisfiable)
    }
}
pub fn nat_to_limbs < ' a , F : PrimeField > ( nat : & Integer , limb_width : usize , n_limbs : usize , ) -> Result < Vec < F > , SynthesisError > { let mask = int_with_n_ones ( limb_width ) ; let mut nat = nat . clone ( ) ; if nat . significant_bits ( ) as usize <= n_limbs * limb_width { Ok ( ( 0 .. n_limbs ) . map ( | _ | { let r = Integer :: from ( & nat & & mask ) ; nat >>= limb_width as u32 ; nat_to_f ( & r ) . unwrap ( ) } ) . collect ( ) ) } else { eprintln ! ( " " nat n_limbs limb_width ) ; Err ( SynthesisError :: Unsatisfiable ) } }
Compute the limbs encoding a natural number.
Compute the limbs encoding a natural number .
nat
&Integer
limb_width
usize
n_limbs
usize
nat
&Integer
limb_width
usize
n_limbs
usize