fn twos_complement_big_int(
        decimal: &CStr,
        length: usize,
        digits: &mut Vec<u8>,
    ) -> FixedLenByteArray {
        use atoi::FromRadix10Signed;

        digits.clear();
        digits.extend(decimal.to_bytes().iter().filter(|&&c| c != b'.'));

        let (num, _consumed) = BigInt::from_radix_10_signed(&digits);
        let mut out = num.to_signed_bytes_be();

        let num_leading_bytes = length - out.len();
        let fill: u8 = if num.sign() == num_bigint::Sign::Minus {
            255
        } else {
            0
        };
        out.resize(length, fill);
        out.rotate_right(num_leading_bytes);
        // Vec<u8> -> ByteArray -> FixedByteArray
        let out: ByteArray = out.into();
        out.into()
    }
// Use num big int to calculate the two complements of arbitrary size
Use num big int to calculate the two complements of arbitrary size
Use num big int to calculate the two complements of arbitrary size
fn twos_complement_big_int(
        decimal: &CStr,
        length: usize,
        digits: &mut Vec<u8>,
    ) -> FixedLenByteArray {
        use atoi::FromRadix10Signed;
        digits.clear();
        digits.extend(decimal.to_bytes().iter().filter(|&&c| c != b'.'));
        let (num, _consumed) = BigInt::from_radix_10_signed(&digits);
        let mut out = num.to_signed_bytes_be();
        let num_leading_bytes = length - out.len();
        let fill: u8 = if num.sign() == num_bigint::Sign::Minus {
            255
        } else {
            0
        };
        out.resize(length, fill);
        out.rotate_right(num_leading_bytes);
        // Vec<u8> -> ByteArray -> FixedByteArray
        let out: ByteArray = out.into();
        out.into()
    }
fn twos_complement_big_int ( decimal : & CStr , length : usize , digits : & mut Vec < u8 > , ) -> FixedLenByteArray { use atoi :: FromRadix10Signed ; digits . clear ( ) ; digits . extend ( decimal . to_bytes ( ) . iter ( ) . filter ( | & & c | c != b'.' ) ) ; let ( num , _consumed ) = BigInt :: from_radix_10_signed ( & digits ) ; let mut out = num . to_signed_bytes_be ( ) ; let num_leading_bytes = length - out . len ( ) ; let fill : u8 = if num . sign ( ) == num_bigint :: Sign :: Minus { 255 } else { 0 } ; out . resize ( length , fill ) ; out . rotate_right ( num_leading_bytes ) ; // Vec<u8> -> ByteArray -> FixedByteArray let out : ByteArray = out . into ( ) ; out . into ( ) }
Use num big int to calculate the two complements of arbitrary size
Use num big int to calculate the two complements of arbitrary size
decimal
&CStr
length
usize
digits
&mut Vec<u8>
decimal
&CStr
length
usize
digits
&mut Vec<u8>