factor/library/math/parse-numbers.facts

71 lines
3.2 KiB
Plaintext

USING: help math math-internals prettyprint ;
HELP: base>
{ $values { "str" "a string" } { "radix" "an integer between 2 and 36" } { "n/f" "a real number or " { $link f } } }
{ $description "Creates a real number from a string representation with the given radix. The radix is ignored for floating point literals; they are always taken to be in base 10."
$terpri
"Outputs " { $link f } " if the string does not represent a number." }
{ $see-also >base } ;
HELP: string>number
{ $values { "str" "a string" } { "n/f" "a real number or " { $link f } } }
{ $description "Creates a real number from a string representation of a number in base 10."
$terpri
"Outputs " { $link f } " if the string does not represent a number." }
{ $see-also number>string } ;
HELP: bin>
{ $values { "str" "a string" } { "n/f" "a real number or " { $link f } } }
{ $description "Creates a real number from a string representation of a number in base 2."
$terpri
"Outputs " { $link f } " if the string does not represent a number." }
{ $see-also POSTPONE: BIN: } ;
HELP: oct>
{ $values { "str" "a string" } { "n/f" "a real number or " { $link f } } }
{ $description "Creates a real number from a string representation of a number in base 8."
$terpri
"Outputs " { $link f } " if the string does not represent a number." }
{ $see-also POSTPONE: OCT: } ;
HELP: hex>
{ $values { "str" "a string" } { "n" "a real number" } }
{ $description "Creates a real number from a string representation of a number in base 16."
$terpri
"Outputs " { $link f } " if the string does not represent a number." }
{ $see-also POSTPONE: HEX: } ;
HELP: >base
{ $values { "n" "a real number" } { "radix" "an integer between 2 and 36" } { "str" "a string" } }
{ $description "Converts a real number into a string representation using the given radix. If the number is a float, the radix is ignored and the output is always in base 10." }
{ $see-also base> } ;
HELP: number>string
{ $values { "n" "a real number" } { "str" "a string" } }
{ $description "Outputs a string representation of a number using base 10." } ;
HELP: >bin
{ $values { "n" "a real number" } { "str" "a string" } }
{ $description "Outputs a string representation of a number using base 2." }
{ $see-also .b } ;
HELP: >oct
{ $values { "n" "a real number" } { "str" "a string" } }
{ $description "Outputs a string representation of a number using base 8." }
{ $see-also .o } ;
HELP: >hex
{ $values { "n" "a real number" } { "str" "a string" } }
{ $description "Outputs a string representation of a number using base 16." }
{ $see-also .h } ;
HELP: string>float ( n -- str )
{ $values { "str" "a string" } { "n/f" "a real number or " { $link f } } }
{ $description "Primitive for creating a float from a string representation. User code should call " { $link string>number } " instead, since it is polymorphic and can handle other types of numbers."
$terpri
"Outputs " { $link f } " if the string does not represent a float." } ;
HELP: float>string ( n -- str )
{ $values { "n" "a real number" } { "str" "a string" } }
{ $description "Primitive for getting a string representation of a float. User code should call " { $link number>string } " instead, since it is polymorphic and can handle other types of numbers." } ;