]> gitweb.factorcode.org Git - factor.git/blob - core/math/ratios/ratios-docs.factor
57b37f1bb7ab71bd25a72da8c175e2828b6238ee
[factor.git] / core / math / ratios / ratios-docs.factor
1 USING: help.markup help.syntax math math.private
2 math.ratios.private math.functions ;
3 IN: math.ratios
4
5 ARTICLE: "rationals" "Rational numbers"
6 { $subsections ratio }
7 "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:"
8 { $example "1210 11 / ." "110" }
9 { $example "100 330 / ." "10/33" }
10 { $example "14 10 / ." "1+2/5" }
11 "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."
12 $nl
13 "Ratios behave just like any other number -- all numerical operations work as you would expect."
14 { $example "1/2 1/3 + ." "5/6" }
15 { $example "100 6 / 3 * ." "50" }
16 "Ratios can be taken apart:"
17 { $subsections
18     numerator
19     denominator
20     >fraction
21 }
22 { $see-also "syntax-ratios" } ;
23
24 ABOUT: "rationals"
25
26 HELP: ratio
27 { $class-description "The class of rational numbers with denominator not equal to 1." } ;
28
29 HELP: rational
30 { $class-description "The class of rational numbers, a disjoint union of integers and ratios." } ;
31
32 HELP: numerator
33 { $values { "a/b" rational } { "a" integer } }
34 { $description "Outputs the numerator of a rational number. Acts as the identity on integers." } ;
35
36 HELP: denominator
37 { $values { "a/b" rational } { "b" "a positive integer" } }
38 { $description "Outputs the denominator of a rational number. Always outputs 1 with integers." } ;
39
40 HELP: fraction>
41 { $values { "a" integer } { "b" "a positive integer" } { "a/b" rational } }
42 { $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." } ;
43
44 HELP: >fraction
45 { $values { "a/b" rational } { "a" integer } { "b" "a positive integer" } }
46 { $description "Extracts the numerator and denominator of a rational number." } ;
47
48 HELP: 2>fraction
49 { $values { "a/b" rational } { "c/d" rational } { "a" integer } { "c" integer } { "b" "a positive integer" } { "d" "a positive integer" } }
50 { $description "Extracts the numerator and denominator of two rational numbers at once." } ;