]> gitweb.factorcode.org Git - factor.git/blob - core/math/ratios/ratios-docs.factor
core: trim using lists with tool
[factor.git] / core / math / ratios / ratios-docs.factor
1 USING: help.markup help.syntax math math.ratios.private ;
2 IN: math.ratios
3
4 ARTICLE: "rationals" "Rational numbers"
5 { $subsections ratio }
6 "When we add, subtract or multiply any two integers, the result is always an integer. However, dividing a numerator by a denominator that is not an integral divisor of the denominator yields a ratio:"
7 { $example "1210 11 / ." "110" }
8 { $example "100 330 / ." "10/33" }
9 { $example "14 10 / ." "1+2/5" }
10 "Ratios are printed and can be input literally in the form above. Ratios are always reduced to lowest terms by factoring out the greatest common divisor of the numerator and denominator. A ratio with a denominator of 1 becomes an integer. Division with a denominator of 0 throws an error."
11 $nl
12 "Ratios behave just like any other number -- all numerical operations work as you would expect."
13 { $example "1/2 1/3 + ." "5/6" }
14 { $example "100 6 / 3 * ." "50" }
15 "Ratios can be taken apart:"
16 { $subsections
17     numerator
18     denominator
19     >fraction
20 }
21 { $see-also "syntax-ratios" } ;
22
23 ABOUT: "rationals"
24
25 HELP: ratio
26 { $class-description "The class of rational numbers with denominator not equal to 1." } ;
27
28 HELP: rational
29 { $class-description "The class of rational numbers, a disjoint union of integers and ratios." } ;
30
31 HELP: numerator
32 { $values { "a/b" rational } { "a" integer } }
33 { $description "Outputs the numerator of a rational number. Acts as the identity on integers." } ;
34
35 HELP: denominator
36 { $values { "a/b" rational } { "b" "a positive integer" } }
37 { $description "Outputs the denominator of a rational number. Always outputs 1 with integers." } ;
38
39 HELP: fraction>
40 { $values { "a" integer } { "b" "a positive integer" } { "a/b" rational } }
41 { $description "Creates a new ratio, or outputs the numerator if the denominator is 1. This word does not reduce the fraction to lowest terms, and should not be called directly; use " { $link / } " instead." } ;
42
43 HELP: >fraction
44 { $values { "a/b" rational } { "a" integer } { "b" "a positive integer" } }
45 { $description "Extracts the numerator and denominator of a rational number." } ;
46
47 HELP: 2>fraction
48 { $values { "a/b" rational } { "c/d" rational } { "a" integer } { "c" integer } { "b" "a positive integer" } { "d" "a positive integer" } }
49 { $description "Extracts the numerator and denominator of two rational numbers at once." } ;