From 78bbf96a6d23ed6799d8a72f93eb2ae30d1c93fd Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 23 Jul 2009 15:54:57 -0500 Subject: [PATCH] move signed-le> to io.binary, clean up using list for math.bitwise --- basis/math/bitwise/bitwise.factor | 13 ++----------- core/io/binary/binary.factor | 7 +++++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/basis/math/bitwise/bitwise.factor b/basis/math/bitwise/bitwise.factor index cea944a6e8..bed065a800 100755 --- a/basis/math/bitwise/bitwise.factor +++ b/basis/math/bitwise/bitwise.factor @@ -1,8 +1,7 @@ ! Copyright (C) 2007, 2008 Slava Pestov, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays assocs kernel math sequences accessors -math.bits sequences.private words namespaces macros -hints combinators fry io.binary combinators.smart ; +USING: arrays assocs combinators combinators.smart fry kernel +macros math math.bits sequences sequences.private words ; IN: math.bitwise ! utilities @@ -104,14 +103,6 @@ PRIVATE> : bit-count ( x -- n ) 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 ) - signed-le> ; - : >signed ( x n -- y ) 2dup neg 1 + shift 1 = [ 2^ - ] [ drop ] if ; diff --git a/core/io/binary/binary.factor b/core/io/binary/binary.factor index d2e50c2a6a..cf2781aac0 100644 --- a/core/io/binary/binary.factor +++ b/core/io/binary/binary.factor @@ -24,3 +24,10 @@ IN: io.binary : h>b/b ( h -- b1 b2 ) [ mask-byte ] [ -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 ) + signed-le> ;