]> gitweb.factorcode.org Git - factor.git/blob - basis/math/bits/bits.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / math / bits / bits.factor
1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: sequences kernel math accessors sequences.private ;
4 IN: math.bits
5
6 TUPLE: bits { number read-only } { length read-only } ;
7 C: <bits> bits
8
9 : make-bits ( number -- bits )
10     [ T{ bits f 0 0 } ] [ dup abs log2 1 + <bits> ] if-zero ; inline
11
12 M: bits length length>> ;
13
14 M: bits nth-unsafe number>> swap bit? ;
15
16 INSTANCE: bits immutable-sequence
17
18 : unbits ( seq -- number )
19     <reversed> 0 [ [ 1 shift ] dip [ 1 + ] when ] reduce ;