MCPcopy Create free account
hub / github.com/BitVM/BitVM / resize

Method resize

bitvm/src/bigint/std.rs:366–392  ·  view source on GitHub ↗

Resize positive numbers # Note Does not work for negative numbers

()

Source from the content-addressed store, hash-verified

364 ///
365 /// Does not work for negative numbers
366 pub fn resize<const T_BITS: u32>() -> Script {
367 let n_limbs_self = N_BITS.div_ceil(LIMB_SIZE);
368 let n_limbs_target = T_BITS.div_ceil(LIMB_SIZE);
369
370 match n_limbs_target.cmp(&n_limbs_self) {
371 Ordering::Equal => script! {},
372 Ordering::Greater => {
373 let n_limbs_to_add = n_limbs_target - n_limbs_self;
374 script! {
375 if n_limbs_to_add > 0 {
376 {0} {crate::pseudo::OP_NDUP((n_limbs_to_add - 1) as usize)} // Pushing zeros to the stack
377 }
378 for _ in 0..n_limbs_self {
379 { n_limbs_target - 1 } OP_ROLL
380 }
381 }
382 }
383 Ordering::Less => {
384 let n_limbs_to_remove = n_limbs_self - n_limbs_target;
385 script! {
386 for _ in 0..n_limbs_to_remove {
387 { n_limbs_target } OP_ROLL OP_DROP
388 }
389 }
390 }
391 }
392 }
393
394 /// Generates a vector of TransformStep struct that encodes all the information needed to
395 /// convert BigInt form one limbsize represention (source) to another (target).

Callers 2

push_u32_leMethod · 0.80
read_u32_leMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected