This commit is contained in:
2026-08-30 12:22:00 +03:00
parent 8f607afb3c
commit b18dacec07
7 changed files with 403 additions and 53 deletions
+31
View File
@@ -699,4 +699,35 @@ mod tests {
assert_eq!(p.word_size(), WordSize::Dint);
assert_eq!(p.dec_text().replace(' ', ""), "-1");
}
#[test]
fn shift_count_mods_word_size() {
// Locks hardware-style semantics: shift count is taken modulo the
// word size (1 << 100000000 → 1e8 % 64 == 0 → no shift).
let mut p = Programmer::new();
p.input_digit('1');
p.set_op(ProgOp::Lsh);
for ch in "100000000".chars() {
p.input_digit(ch);
}
p.equals();
assert_eq!(p.current_bits(), 1);
}
#[test]
fn shift_out_of_word_gives_zero() {
// 0xFFFF_FFFF_FFFF_FFFF Lsh 63 → only bit 0 survives at bit 63.
let mut p = Programmer::new();
p.set_base(Base::Hex);
for ch in "FFFFFFFFFFFFFFFF".chars() {
p.input_digit(ch);
}
p.set_op(ProgOp::Lsh);
p.set_base(Base::Dec); // type the shift count in decimal
p.input_digit('6');
p.input_digit('3');
p.equals();
// (u64::MAX << 63) & u64::MAX = 0x8000_0000_0000_0000
assert_eq!(p.current_bits(), 0x8000_0000_0000_0000);
}
}