math.parser: hex> etc. shouldn't take radix prefix

Fixes #453
db4
Joe Groff 2011-12-16 17:20:05 -08:00
parent ddd7df2a38
commit c4bd4dc1cc
2 changed files with 34 additions and 3 deletions

View File

@ -333,3 +333,26 @@ unit-test
[ -0x1.0000,0000,0000,2p0 ] [ "-0x1.0000,0000,0000,1,Cp0" string>number ] unit-test
[ -0x1.0000,0000,0000,2p0 ] [ "-0x1.0000,0000,0000,1,81p0" string>number ] unit-test
[ -0x1.0000,0000,0000,2p0 ] [ "-0x1.0000,0000,0000,1,8000,0000,0000,0001p0" string>number ] unit-test
! #453
! hex> dec> oct> bin> shouldn't admit radix prefixes
[ 0x0b ] [ "0b" hex> ] unit-test
[ 0x0b0 ] [ "0b0" hex> ] unit-test
[ f ] [ "0o0" hex> ] unit-test
[ f ] [ "0x0" hex> ] unit-test
[ f ] [ "0b" dec> ] unit-test
[ f ] [ "0b0" dec> ] unit-test
[ f ] [ "0o0" dec> ] unit-test
[ f ] [ "0x0" dec> ] unit-test
[ f ] [ "0b" oct> ] unit-test
[ f ] [ "0b0" oct> ] unit-test
[ f ] [ "0o0" oct> ] unit-test
[ f ] [ "0x0" oct> ] unit-test
[ f ] [ "0b" bin> ] unit-test
[ f ] [ "0b0" bin> ] unit-test
[ f ] [ "0o0" bin> ] unit-test
[ f ] [ "0x0" bin> ] unit-test

View File

@ -267,12 +267,20 @@ DEFER: @neg-digit
[ @pos-first-digit ]
} case ; inline
: @first-char-no-radix ( i number-parse n char -- n/f )
{
{ CHAR: - [ [ @neg-digit ] require-next-digit ?neg ] }
{ CHAR: + [ [ @pos-digit ] require-next-digit ] }
[ @pos-digit ]
} case ; inline
PRIVATE>
: base> ( str radix -- n/f )
<number-parse> [ @first-char ] require-next-digit ;
: string>number ( str -- n/f )
10 <number-parse> [ @first-char ] require-next-digit ;
: string>number ( str -- n/f ) 10 base> ; inline
: base> ( str radix -- n/f )
<number-parse> [ @first-char-no-radix ] require-next-digit ;
: bin> ( str -- n/f ) 2 base> ; inline
: oct> ( str -- n/f ) 8 base> ; inline