fix each-bit for negative inputs
parent
c52cffea19
commit
2883f8a5f5
|
@ -215,7 +215,7 @@ vectors words ;
|
||||||
"/library/collections/strings.facts"
|
"/library/collections/strings.facts"
|
||||||
"/library/collections/tree-each.facts"
|
"/library/collections/tree-each.facts"
|
||||||
"/library/collections/vectors.facts"
|
"/library/collections/vectors.facts"
|
||||||
"/library/collections/virtual-sequence.facts"
|
"/library/collections/virtual-sequences.facts"
|
||||||
|
|
||||||
"/library/syntax/parse-syntax.factor"
|
"/library/syntax/parse-syntax.factor"
|
||||||
|
|
||||||
|
|
|
@ -95,9 +95,6 @@ M: simple-element print-element [ print-element ] each ;
|
||||||
: textual-list ( seq quot -- )
|
: textual-list ( seq quot -- )
|
||||||
[ "," format* bl ] interleave ; inline
|
[ "," format* bl ] interleave ; inline
|
||||||
|
|
||||||
: $see-also ( content -- )
|
|
||||||
"See also" $subheading [ 1array $link ] textual-list ;
|
|
||||||
|
|
||||||
: $see ( content -- )
|
: $see ( content -- )
|
||||||
terpri*
|
terpri*
|
||||||
code-style [ [ first see ] with-nesting* ] with-style
|
code-style [ [ first see ] with-nesting* ] with-style
|
||||||
|
@ -142,6 +139,9 @@ DEFER: help
|
||||||
: $definition ( content -- )
|
: $definition ( content -- )
|
||||||
"Definition" $subheading $see ;
|
"Definition" $subheading $see ;
|
||||||
|
|
||||||
|
: $see-also ( content -- )
|
||||||
|
"See also" $subheading [ 1array $link ] textual-list ;
|
||||||
|
|
||||||
: $predicate ( content -- )
|
: $predicate ( content -- )
|
||||||
{ { "object" "an object" } } $values
|
{ { "object" "an object" } } $values
|
||||||
"Tests if the top of the stack is " $description
|
"Tests if the top of the stack is " $description
|
||||||
|
|
|
@ -29,7 +29,7 @@ M: number ^ ( z w -- z^w )
|
||||||
: each-bit ( n quot -- | quot: 0/1 -- )
|
: each-bit ( n quot -- | quot: 0/1 -- )
|
||||||
#! Apply the quotation to each bit of the number. The number
|
#! Apply the quotation to each bit of the number. The number
|
||||||
#! must be positive.
|
#! must be positive.
|
||||||
over 0 number= [
|
over 0 number= pick -1 number= or [
|
||||||
2drop
|
2drop
|
||||||
] [
|
] [
|
||||||
2dup >r >r >r 1 bitand r> call r> -1 shift r> each-bit
|
2dup >r >r >r 1 bitand r> call r> -1 shift r> each-bit
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
IN: temporary
|
IN: temporary
|
||||||
USING: kernel math prettyprint test ;
|
USING: kernel math namespaces prettyprint test ;
|
||||||
|
|
||||||
[ "-8" ] [ -8 unparse ] unit-test
|
[ "-8" ] [ -8 unparse ] unit-test
|
||||||
|
|
||||||
|
@ -97,3 +97,5 @@ unit-test
|
||||||
[ 0 ] [ -1 -268435456 >fixnum /i ] unit-test
|
[ 0 ] [ -1 -268435456 >fixnum /i ] unit-test
|
||||||
[ 0 -1 ] [ -1 -268435456 >fixnum /mod ] unit-test
|
[ 0 -1 ] [ -1 -268435456 >fixnum /mod ] unit-test
|
||||||
[ 14355 ] [ 1591517158873146351817850880000000 32769 mod ] unit-test
|
[ 14355 ] [ 1591517158873146351817850880000000 32769 mod ] unit-test
|
||||||
|
|
||||||
|
[ { 0 1 1 0 } ] [ [ -10 [ , ] each-bit ] { } make ] unit-test
|
||||||
|
|
Loading…
Reference in New Issue