pub fn bn_to_gen(bn: &BigInt) -> GEN {
    let neg1 = if bn < &BigInt::zero() { -1 } else { 1 };
    let neg_bn: BigInt = if bn < &BigInt::zero() {
        -BigInt::one()
    } else {
        BigInt::one()
    };
    let bn: BigInt = bn * &neg_bn;

    let bn_len = bn.bit_length();
    let num_int_bound: usize;
    if bn_len % 8 == 0 {
        num_int_bound = bn_len / 8;
    } else {
        num_int_bound = bn_len / 8 + 1;
    }
    let size_int = 32;
    let two_bn = BigInt::from(2);
    let all_ones_32bits = two_bn.pow(size_int as u32) - BigInt::one();
    let mut array = [0u8; 4];
    let ints_vec = (0..num_int_bound)
        .map(|i| {
            let masked_valued_bn =
                (bn.clone() & all_ones_32bits.clone() << (i * size_int)) >> (i * size_int);

            let mut masked_value_bytes = BigInt::to_vec(&masked_valued_bn);
            // padding if int has leading zero bytes
            let mut template = vec![0; 4 - masked_value_bytes.len()];
            template.extend_from_slice(&masked_value_bytes);
            masked_value_bytes = template;

            array.copy_from_slice(&masked_value_bytes[..]);

            u32::from_be_bytes(array) as i64
        })
        .collect::<Vec<i64>>();

    let mut i = 0;
    let mut gen = unsafe { mkintn(1i64, 0i64) };
    unsafe {
        while i < num_int_bound {
            let elem1 = mkintn(1i64, ints_vec[num_int_bound - i - 1]);
            let elem2 = shifti(gen, (size_int) as i64);
            gen = gadd(elem1, elem2);
            i = i + 1
        }

        if neg1 == -1 {
            gen = gneg(gen);
        }

        return gen;
    }
}
// helper functions:
// this function turns a bigint into GEN (native Pari type)
helper functions:
this function turns a bigint into GEN (native Pari type)
helper functions : this function turns a bigint into GEN ( native Pari type )
pub fn bn_to_gen(bn: &BigInt) -> GEN {
    let neg1 = if bn < &BigInt::zero() { -1 } else { 1 };
    let neg_bn: BigInt = if bn < &BigInt::zero() {
        -BigInt::one()
    } else {
        BigInt::one()
    };
    let bn: BigInt = bn * &neg_bn;
    let bn_len = bn.bit_length();
    let num_int_bound: usize;
    if bn_len % 8 == 0 {
        num_int_bound = bn_len / 8;
    } else {
        num_int_bound = bn_len / 8 + 1;
    }
    let size_int = 32;
    let two_bn = BigInt::from(2);
    let all_ones_32bits = two_bn.pow(size_int as u32) - BigInt::one();
    let mut array = [0u8; 4];
    let ints_vec = (0..num_int_bound)
        .map(|i| {
            let masked_valued_bn =
                (bn.clone() & all_ones_32bits.clone() << (i * size_int)) >> (i * size_int);
            let mut masked_value_bytes = BigInt::to_vec(&masked_valued_bn);
            // padding if int has leading zero bytes
            let mut template = vec![0; 4 - masked_value_bytes.len()];
            template.extend_from_slice(&masked_value_bytes);
            masked_value_bytes = template;
            array.copy_from_slice(&masked_value_bytes[..]);
            u32::from_be_bytes(array) as i64
        })
        .collect::<Vec<i64>>();
    let mut i = 0;
    let mut gen = unsafe { mkintn(1i64, 0i64) };
    unsafe {
        while i < num_int_bound {
            let elem1 = mkintn(1i64, ints_vec[num_int_bound - i - 1]);
            let elem2 = shifti(gen, (size_int) as i64);
            gen = gadd(elem1, elem2);
            i = i + 1
        }
        if neg1 == -1 {
            gen = gneg(gen);
        }
        return gen;
    }
}
pub fn bn_to_gen ( bn : & BigInt ) -> GEN { let neg1 = if bn < & BigInt :: zero ( ) { - 1 } else { 1 } ; let neg_bn : BigInt = if bn < & BigInt :: zero ( ) { - BigInt :: one ( ) } else { BigInt :: one ( ) } ; let bn : BigInt = bn * & neg_bn ; let bn_len = bn . bit_length ( ) ; let num_int_bound : usize ; if bn_len % 8 == 0 { num_int_bound = bn_len / 8 ; } else { num_int_bound = bn_len / 8 + 1 ; } let size_int = 32 ; let two_bn = BigInt :: from ( 2 ) ; let all_ones_32bits = two_bn . pow ( size_int as u32 ) - BigInt :: one ( ) ; let mut array = [ 0u8 ; 4 ] ; let ints_vec = ( 0 .. num_int_bound ) . map ( | i | { let masked_valued_bn = ( bn . clone ( ) & all_ones_32bits . clone ( ) << ( i * size_int ) ) >> ( i * size_int ) ; let mut masked_value_bytes = BigInt :: to_vec ( & masked_valued_bn ) ; // padding if int has leading zero bytes let mut template = vec ! [ 0 4 masked_value_bytes len ( ) ] ; template . extend_from_slice ( & masked_value_bytes ) ; masked_value_bytes = template ; array . copy_from_slice ( & masked_value_bytes [ .. ] ) ; u32 :: from_be_bytes ( array ) as i64 } ) . collect :: < Vec < i64 > > ( ) ; let mut i = 0 ; let mut gen = unsafe { mkintn ( 1i64 , 0i64 ) } ; unsafe { while i < num_int_bound { let elem1 = mkintn ( 1i64 , ints_vec [ num_int_bound - i - 1 ] ) ; let elem2 = shifti ( gen , ( size_int ) as i64 ) ; gen = gadd ( elem1 , elem2 ) ; i = i + 1 } if neg1 == - 1 { gen = gneg ( gen ) ; } return gen ; } }
helper functions:
this function turns a bigint into GEN (native Pari type)
helper functions : this function turns a bigint into GEN ( native Pari type )
bn
&BigInt
bn
&BigInt