math.parser: simplify { integer ratio } >base.
parent
89e3cc511e
commit
0dbc5e7d67
|
@ -420,24 +420,19 @@ GENERIC# >base 1 ( n radix -- str )
|
||||||
: >hex ( n -- str ) 16 >base ; inline
|
: >hex ( n -- str ) 16 >base ; inline
|
||||||
|
|
||||||
M: integer >base
|
M: integer >base
|
||||||
over 0 = [
|
{
|
||||||
2drop "0"
|
{ [ over 0 = ] [ 2drop "0" ] }
|
||||||
] [
|
{ [ over 0 > ] [ positive>base ] }
|
||||||
over 0 > [
|
[ [ neg ] dip positive>base CHAR: - prefix ]
|
||||||
positive>base
|
} cond ;
|
||||||
] [
|
|
||||||
[ neg ] dip positive>base CHAR: - prefix
|
|
||||||
] if
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
M: ratio >base
|
M: ratio >base
|
||||||
[ [ 0 < ] [ abs 1 /mod ] bi ]
|
[ >fraction [ /mod ] keep ] [ [ >base ] curry tri@ ] bi*
|
||||||
[ [ positive>base ] curry ] bi*
|
"/" glue over first-unsafe {
|
||||||
[
|
{ CHAR: 0 [ nip ] }
|
||||||
[ [ numerator ] [ denominator ] bi ] dip bi@ "/" glue
|
{ CHAR: - [ append ] }
|
||||||
] keep rot [ drop ] [
|
[ drop "+" glue ]
|
||||||
swap call pick "-" "+" ? rot 3append
|
} case ;
|
||||||
] if-zero swap [ CHAR: - prefix ] when ;
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue