math.parser: don't use variables in M\ ratio >base.
parent
47a5619bb4
commit
ff72d10fda
|
@ -402,20 +402,6 @@ GENERIC# >base 1 ( n radix -- str )
|
||||||
: >oct ( n -- str ) 8 >base ; inline
|
: >oct ( n -- str ) 8 >base ; inline
|
||||||
: >hex ( n -- str ) 16 >base ; inline
|
: >hex ( n -- str ) 16 >base ; inline
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
SYMBOL: radix
|
|
||||||
SYMBOL: negative?
|
|
||||||
|
|
||||||
: sign ( -- str ) negative? get "-" "+" ? ;
|
|
||||||
|
|
||||||
: with-radix ( radix quot -- )
|
|
||||||
radix swap with-variable ; inline
|
|
||||||
|
|
||||||
: (>base) ( n -- str ) radix get positive>base ;
|
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
M: integer >base
|
M: integer >base
|
||||||
over 0 = [
|
over 0 = [
|
||||||
2drop "0"
|
2drop "0"
|
||||||
|
@ -428,17 +414,13 @@ M: integer >base
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: ratio >base
|
M: ratio >base
|
||||||
|
[ [ 0 < ] [ abs 1 /mod ] bi ]
|
||||||
|
[ [ positive>base ] curry ] bi*
|
||||||
[
|
[
|
||||||
dup 0 < negative? set
|
[ [ numerator ] [ denominator ] bi ] dip bi@ "/" glue
|
||||||
abs 1 /mod
|
] keep rot [ drop ] [
|
||||||
[ [ "" ] [ (>base) sign append ] if-zero ]
|
swap call pick "-" "+" ? rot 3append
|
||||||
[
|
] if-zero swap [ CHAR: - prefix ] when ;
|
||||||
[ numerator (>base) ]
|
|
||||||
[ denominator (>base) ] bi
|
|
||||||
"/" glue
|
|
||||||
] bi* append
|
|
||||||
negative? get [ CHAR: - prefix ] when
|
|
||||||
] with-radix ;
|
|
||||||
|
|
||||||
: fix-float ( str -- newstr )
|
: fix-float ( str -- newstr )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue