Handbook
Glossary
>base ( n radix -- str )
Factor handbook
»
The language
»
Numbers
»
Converting between numbers and strings
Prev:
>hex ( n -- str )
Next:
string>number ( str -- n/f )
Vocabulary
math
.
parser
Inputs
n
a
real
radix
an integer between 2 and 16
Outputs
str
a
string
Word description
Converts a real number into a string representation using the given radix. If the number is a
float
, the radix can be either base 10 or base 16.
See also
base>
Definition
IN:
math.parser
GENERIC#:
>base
1
( n radix -- str )
Methods
USING:
combinators
kernel
math
math.parser
math.parser.private
;
M:
float
>base
{
{
[
over
fp-nan?
]
[
drop
fp-sign
"-0/0."
"0/0."
?
]
}
{
[
over
1/0.
=
]
[
2drop
"1/0."
]
}
{
[
over
-1/0.
=
]
[
2drop
"-1/0."
]
}
{
[
over
0.0
fp-bitwise=
]
[
2drop
"0.0"
]
}
{
[
over
-0.0
fp-bitwise=
]
[
2drop
"-0.0"
]
}
[
float>base
]
}
cond
;
USING:
combinators
kernel
math
math.parser
math.parser.private
sequences
;
M:
integer
>base
{
{
[
over
0
=
]
[
2drop
"0"
]
}
{
[
over
0
>
]
[
positive>base
]
}
[
[
neg
]
dip
positive>base
45
prefix
]
}
cond
;
USING:
combinators
kernel
math
math.parser
sequences
sequences.private
;
M:
ratio
>base
[
>fraction
[
/mod
]
keep
]
[
[
>base
]
curry
tri@
]
bi*
"/"
glue
over
first-unsafe
{
{
48
[
nip
]
}
{
45
[
append
]
}
[
drop
"+"
glue
]
}
case
;