better error reporting for DECIMAL:
parent
7e4a34ca3e
commit
73352a3437
|
@ -15,17 +15,14 @@ IN: money
|
||||||
"." % number>string 2 CHAR: 0 pad-left %
|
"." % number>string 2 CHAR: 0 pad-left %
|
||||||
] "" make print ;
|
] "" make print ;
|
||||||
|
|
||||||
TUPLE: not-a-decimal ;
|
ERROR: not-a-decimal x ;
|
||||||
|
|
||||||
: not-a-decimal ( -- * )
|
|
||||||
T{ not-a-decimal } throw ;
|
|
||||||
|
|
||||||
: parse-decimal ( str -- ratio )
|
: parse-decimal ( str -- ratio )
|
||||||
"." split1
|
"." split1
|
||||||
>r dup "-" head? [ drop t "0" ] [ f swap ] if r>
|
>r dup "-" head? [ drop t "0" ] [ f swap ] if r>
|
||||||
[ dup empty? [ drop "0" ] when ] bi@
|
[ dup empty? [ drop "0" ] when ] bi@
|
||||||
dup length
|
dup length
|
||||||
>r [ string>number dup [ not-a-decimal ] unless ] bi@ r>
|
>r [ dup string>number [ nip ] [ not-a-decimal ] if* ] bi@ r>
|
||||||
10 swap ^ / + swap [ neg ] when ;
|
10 swap ^ / + swap [ neg ] when ;
|
||||||
|
|
||||||
: DECIMAL:
|
: DECIMAL:
|
||||||
|
|
Loading…
Reference in New Issue