math.parser: remove digits>integer.

db4
John Benediktsson 2015-07-19 18:06:51 -07:00
parent b5a671cd88
commit 296974a057
2 changed files with 6 additions and 24 deletions

View File

@ -28,11 +28,6 @@ $nl
ABOUT: "number-strings" ABOUT: "number-strings"
HELP: digits>integer
{ $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 16" } { "n/f" { $maybe integer } } }
{ $description "Converts a sequence of digits (with most significant digit first) into an integer." }
{ $notes "This is one of the factors of " { $link string>number } "." } ;
HELP: >digit HELP: >digit
{ $values { "n" "an integer between 0 and 15" } { "ch" "a character" } } { $values { "n" "an integer between 0 and 15" } { "ch" "a character" } }
{ $description "Outputs a character representation of a digit." } { $description "Outputs a character representation of a digit." }

View File

@ -16,6 +16,12 @@ PRIVATE>
[ CHAR: a 10 - - dup 10 < [ drop 255 ] when ] [ CHAR: a 10 - - dup 10 < [ drop 255 ] when ]
} cond ; inline } cond ; inline
: string>digits ( str -- digits )
[ digit> ] B{ } map-as ; inline
: >digit ( n -- ch )
dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] if ; inline
ERROR: invalid-radix radix ; ERROR: invalid-radix radix ;
<PRIVATE <PRIVATE
@ -307,25 +313,6 @@ PRIVATE>
: dec> ( str -- n/f ) 10 base> ; inline : dec> ( str -- n/f ) 10 base> ; inline
: hex> ( str -- n/f ) 16 base> ; inline : hex> ( str -- n/f ) 16 base> ; inline
: string>digits ( str -- digits )
[ digit> ] B{ } map-as ; inline
<PRIVATE
: (digits>integer) ( valid? accum digit radix -- valid? accum )
2dup < [ swapd * + ] [ 4drop f 0 ] if ; inline
: each-digit ( seq radix quot -- n/f )
[ t 0 ] 3dip curry each swap [ drop f ] unless ; inline
PRIVATE>
: digits>integer ( seq radix -- n/f )
[ (digits>integer) ] each-digit ; inline
: >digit ( n -- ch )
dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] if ; inline
<PRIVATE <PRIVATE
CONSTANT: TENS B{ CONSTANT: TENS B{