move signed-le> to io.binary, clean up using list for math.bitwise

db4
Doug Coleman 2009-07-23 15:54:57 -05:00
parent bad8e05937
commit 78bbf96a6d
2 changed files with 9 additions and 11 deletions

View File

@ -1,8 +1,7 @@
! Copyright (C) 2007, 2008 Slava Pestov, Doug Coleman. ! Copyright (C) 2007, 2008 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs kernel math sequences accessors USING: arrays assocs combinators combinators.smart fry kernel
math.bits sequences.private words namespaces macros macros math math.bits sequences sequences.private words ;
hints combinators fry io.binary combinators.smart ;
IN: math.bitwise IN: math.bitwise
! utilities ! utilities
@ -104,14 +103,6 @@ PRIVATE>
: bit-count ( x -- n ) : bit-count ( x -- n )
dup 0 < [ bitnot ] when (bit-count) ; inline dup 0 < [ bitnot ] when (bit-count) ; inline
! Signed byte array to integer conversion
: signed-le> ( bytes -- x )
[ le> ] [ length 8 * 1 - on-bits ] bi
2dup > [ bitnot bitor ] [ drop ] if ;
: signed-be> ( bytes -- x )
<reversed> signed-le> ;
: >signed ( x n -- y ) : >signed ( x n -- y )
2dup neg 1 + shift 1 = [ 2^ - ] [ drop ] if ; 2dup neg 1 + shift 1 = [ 2^ - ] [ drop ] if ;

View File

@ -24,3 +24,10 @@ IN: io.binary
: h>b/b ( h -- b1 b2 ) : h>b/b ( h -- b1 b2 )
[ mask-byte ] [ mask-byte ]
[ -8 shift mask-byte ] bi ; [ -8 shift mask-byte ] bi ;
: signed-le> ( bytes -- x )
[ le> ] [ length 8 * 1 - 2^ 1 - ] bi
2dup > [ bitnot bitor ] [ drop ] if ;
: signed-be> ( bytes -- x )
<reversed> signed-le> ;