factor/library/math/ratio.facts

28 lines
1.3 KiB
Plaintext

USING: help math math-internals ;
HELP: ratio
{ $class-description "The class of rational numbers with denominator not equal to 1." } ;
HELP: rational
{ $class-description "The class of rational numbers, a disjoint union of integers and ratios." } ;
HELP: numerator ( a/b -- a )
{ $values { "a/b" "a rational number" } { "a" "an integer" } }
{ $description "Outputs the numerator of a rational number. Acts as the identity on integers." } ;
HELP: denominator ( a/b -- b )
{ $values { "a/b" "a rational number" } { "b" "a positive integer" } }
{ $description "Outputs the denominator of a rational number. Always outputs 1 with integers." } ;
HELP: >fraction
{ $values { "a/b" "a rational number" } { "a" "an integer" } { "b" "a positive integer" } }
{ $description "Extracts the numerator and denominator of a rational number." } ;
HELP: 2>fraction
{ $values { "a/b" "a rational number" } { "a" "an integer" } { "c" "an integer" } { "b" "a positive integer" } { "d" "a positive integer" } }
{ $description "Extracts the numerator and denominator of two rational numbers at once." } ;
HELP: (fraction>) ( a b -- a/b )
{ $values { "a" "an integer" } { "b" "an integer" } { "a/b" "a ratio" } }
{ $description "Primitive ratio constructor. User code should call " { $link / } " to create ratios instead." } ;