on master help sign in
rap
commit41308663cf61dc59031794652041ad99c771d023 authoriko <mail@iko.soy> dateSun 25 Aug 2024, 18:51 (2 years ago) parent0717fcf
1 file changed+18
nock/src/jets.rs+18
nock/src/jets.rs+18
@@ -70,6 +70,7 @@ pub fn generate_jets() -> Jets {
7070 (184331043431916214773639930303095454137, FIL),
7171 (104452959965816676316166435675758878521, LSH),
7272 (84358434946425438379820219100952030132, RSH),
73+ (49642221456321333759873032692286222867, RAP),
7374 ])
7475}
7576
@@ -676,3 +677,20 @@ static RSH: Jet = |_ctx, n| {
676677
677678 Rc::new(Noun::Atom(b >> a.bits()))
678679};
680+
681+static RAP: Jet = |ctx, n| {
682+ let (bloq, b) = n.as_cell().unwrap();
683+ let bloq = bloq.as_u32().unwrap();
684+ let bits = 2u32.pow(bloq);
685+
686+ let mut target = ctx.big_uints.zero.clone();
687+
688+ for el in b.list_iter().collect::<Vec<_>>().iter().rev() {
689+ let el = el.as_atom().unwrap();
690+ if el != &ctx.big_uints.zero {
691+ target = (target << (bits * met(bloq, el.clone()))) | el;
692+ }
693+ }
694+
695+ Rc::new(Noun::Atom(target))
696+};