]> gitweb.factorcode.org Git - factor.git/blob - core/math/math-docs.factor
minor cleanup to some docs.
[factor.git] / core / math / math-docs.factor
1 USING: help.markup help.syntax kernel quotations sequences ;
2 IN: math
3
4 HELP: number=
5 { $values { "x" number } { "y" number } { "?" boolean } }
6 { $description "Tests if two numbers have the same numeric value." }
7 { $notes "This word differs from " { $link = } " in that it disregards differences in type when comparing numbers."
8 $nl
9 "This word performs an unordered comparison on floating point numbers. See " { $link "math.floats.compare" } " for an explanation." }
10 { $examples
11     { $example "USING: math prettyprint ;" "3.0 3 number= ." "t" }
12     { $example "USING: kernel math prettyprint ;" "3.0 3 = ." "f" }
13 } ;
14
15 HELP: <
16 { $values { "x" real } { "y" real } { "?" boolean } }
17 { $description "Tests if " { $snippet "x" } " is less than " { $snippet "y" } "." }
18 { $notes "This word performs an ordered comparison on floating point numbers. See " { $link "math.floats.compare" } " for an explanation." } ;
19
20 HELP: <=
21 { $values { "x" real } { "y" real } { "?" boolean } }
22 { $description "Tests if " { $snippet "x" } " is less than or equal to " { $snippet "y" } "." }
23 { $notes "This word performs an ordered comparison on floating point numbers. See " { $link "math.floats.compare" } " for an explanation." } ;
24
25 HELP: >
26 { $values { "x" real } { "y" real } { "?" boolean } }
27 { $description "Tests if " { $snippet "x" } " is greater than " { $snippet "y" } "." }
28 { $notes "This word performs an ordered comparison on floating point numbers. See " { $link "math.floats.compare" } " for an explanation." } ;
29
30 HELP: >=
31 { $values { "x" real } { "y" real } { "?" boolean } }
32 { $description "Tests if " { $snippet "x" } " is greater than or equal to " { $snippet "y" } "." }
33 { $notes "This word performs an ordered comparison on floating point numbers. See " { $link "math.floats.compare" } " for an explanation." } ;
34
35 HELP: unordered?
36 { $values { "x" real } { "y" real } { "?" boolean } }
37 { $description "Tests if " { $snippet "x" } " is unordered with respect to " { $snippet "y" } ". This can only occur if one or both values is a floating-point Not-a-Number value." } ;
38
39 HELP: u<
40 { $values { "x" real } { "y" real } { "?" boolean } }
41 { $description "Tests if " { $snippet "x" } " is less than " { $snippet "y" } "." }
42 { $notes "This word performs an unordered comparison on floating point numbers. On rational numbers it is equivalent to " { $link < } ". See " { $link "math.floats.compare" } " for an explanation." } ;
43
44 HELP: u<=
45 { $values { "x" real } { "y" real } { "?" boolean } }
46 { $description "Tests if " { $snippet "x" } " is less than or equal to " { $snippet "y" } "." }
47 { $notes "This word performs an unordered comparison on floating point numbers. On rational numbers it is equivalent to " { $link <= } ". See " { $link "math.floats.compare" } " for an explanation." } ;
48
49 HELP: u>
50 { $values { "x" real } { "y" real } { "?" boolean } }
51 { $description "Tests if " { $snippet "x" } " is greater than " { $snippet "y" } "." }
52 { $notes "This word performs an unordered comparison on floating point numbers. On rational numbers it is equivalent to " { $link > } ". See " { $link "math.floats.compare" } " for an explanation." } ;
53
54 HELP: u>=
55 { $values { "x" real } { "y" real } { "?" boolean } }
56 { $description "Tests if " { $snippet "x" } " is greater than or equal to " { $snippet "y" } "." }
57 { $notes "This word performs an unordered comparison on floating point numbers. On rational numbers it is equivalent to " { $link >= } ". See " { $link "math.floats.compare" } " for an explanation." } ;
58
59 HELP: +
60 { $values { "x" number } { "y" number } { "z" number } }
61 { $description
62     "Adds two numbers."
63     { $list
64         "Addition of fixnums may overflow and convert the result to a bignum."
65         "Addition of bignums always yields a bignum."
66         "Addition of floats always yields a float."
67         "Addition of ratios and complex numbers proceeds using the relevant mathematical rules."
68     }
69 } ;
70
71 HELP: -
72 { $values { "x" number } { "y" number } { "z" number } }
73 { $description
74     "Subtracts " { $snippet "y" } " from " { $snippet "x" } "."
75     { $list
76         "Subtraction of fixnums may overflow and convert the result to a bignum."
77         "Subtraction of bignums always yields a bignum."
78         "Subtraction of floats always yields a float."
79         "Subtraction of ratios and complex numbers proceeds using the relevant mathematical rules."
80     }
81 } ;
82
83 HELP: *
84 { $values { "x" number } { "y" number } { "z" number } }
85 { $description
86     "Multiplies two numbers."
87     { $list
88         "Multiplication of fixnums may overflow and convert the result to a bignum."
89         "Multiplication of bignums always yields a bignum."
90         "Multiplication of floats always yields a float."
91         "Multiplication of ratios and complex numbers proceeds using the relevant mathematical rules."
92     }
93 } ;
94
95 HELP: /
96 { $values { "x" number } { "y" number } { "z" number } }
97 { $description
98     "Divides " { $snippet "x" } " by " { $snippet "y" } ", retaining as much precision as possible."
99     { $list
100         "Division of fixnums may yield a ratio, or overflow and yield a bignum."
101         "Division of bignums may yield a ratio."
102         "Division of floats always yields a float."
103         "Division of ratios and complex numbers proceeds using the relevant mathematical rules."
104     }
105 }
106 { $see-also "division-by-zero" } ;
107
108 HELP: /i
109 { $values { "x" real } { "y" real } { "z" integer } }
110 { $description
111     "Divides " { $snippet "x" } " by " { $snippet "y" } ", truncating the result to an integer."
112 }
113 { $see-also "division-by-zero" } ;
114
115 HELP: /f
116 { $values { "x" real } { "y" real } { "z" float } }
117 { $description
118     "Divides " { $snippet "x" } " by " { $snippet "y" } ", representing the result as a floating point number."
119 }
120 { $see-also "division-by-zero" } ;
121
122 HELP: mod
123 { $values { "x" rational } { "y" rational } { "z" rational } }
124 { $description
125     "Computes the remainder of dividing " { $snippet "x" } " by " { $snippet "y" } ", with the remainder being negative if " { $snippet "x" } " is negative."
126     { $list
127         "Modulus of fixnums always yields a fixnum."
128         "Modulus of bignums always yields a bignum."
129         { "Modulus of rationals always yields a rational. In this case, the remainder is computed using the formula " { $snippet "x - (x mod y) * y" } "." }
130     }
131 }
132 { $see-also "division-by-zero" rem } ;
133
134 HELP: /mod
135 { $values { "x" real } { "y" real } { "z" integer } { "w" real } }
136 { $description
137     "Computes the quotient " { $snippet "z" } " and remainder " { $snippet "w" } " of dividing " { $snippet "x" } " by " { $snippet "y" } ", with the remainder being negative if " { $snippet "x" } " is negative."
138     { $list
139         "The quotient of two fixnums may overflow and yield a bignum; the remainder is always a fixnum"
140         "The quotient and remainder of two bignums is always a bignum."
141     }
142 }
143 { $examples
144     { $example "USING: kernel math prettyprint ;" "5 3 /mod [ . ] bi@" "1\n2" }
145     { $example "USING: kernel math prettyprint ;" "5/2 1/3 /mod [ . ] bi@" "7\n1/6" }
146 }
147 { $see-also "division-by-zero" } ;
148
149 HELP: bitand
150 { $values { "x" integer } { "y" integer } { "z" integer } }
151 { $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in both inputs." }
152 { $examples
153     { $example "USING: math prettyprint ;" "0b101 0b10 bitand .b" "0" }
154     { $example "USING: math prettyprint ;" "0b110 0b10 bitand .b" "10" }
155 }
156 { $notes "This word implements bitwise and, so applying it to booleans will throw an error. Boolean and is the " { $link and } " word." } ;
157
158 HELP: bitor
159 { $values { "x" integer } { "y" integer } { "z" integer } }
160 { $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in at least one of the inputs." }
161 { $examples
162     { $example "USING: math prettyprint ;" "0b101 0b10 bitor .b" "111" }
163     { $example "USING: math prettyprint ;" "0b110 0b10 bitor .b" "110" }
164 }
165 { $notes "This word implements bitwise inclusive or, so applying it to booleans will throw an error. Boolean inclusive or is the " { $link and } " word." } ;
166
167 HELP: bitxor
168 { $values { "x" integer } { "y" integer } { "z" integer } }
169 { $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in exactly one of the inputs." }
170 { $examples
171     { $example "USING: math prettyprint ;" "0b101 0b10 bitxor .b" "111" }
172     { $example "USING: math prettyprint ;" "0b110 0b10 bitxor .b" "100" }
173 }
174 { $notes "This word implements bitwise exclusive or, so applying it to booleans will throw an error. Boolean exclusive or is the " { $link xor } " word." } ;
175
176 HELP: shift
177 { $values { "x" integer } { "n" integer } { "y" integer } }
178 { $description "Shifts " { $snippet "x" } " to the left by " { $snippet "n" } " bits if " { $snippet "n" } " is positive, or " { $snippet "-n" } " bits to the right if " { $snippet "n" } " is negative. A left shift of a fixnum may overflow, yielding a bignum. A right shift may result in bits “falling off” the right hand side and being discarded." }
179 { $examples { $example "USING: math prettyprint ;" "0b101 5 shift .b" "10100000" } { $example "USING: math prettyprint ;" "0b11111 -2 shift .b" "111" } } ;
180
181 HELP: bitnot
182 { $values { "x" integer } { "y" integer } }
183 { $description "Computes the bitwise complement of the input; that is, each bit in the input number is flipped." }
184 { $notes "This word implements bitwise not, so applying it to booleans will throw an error. Boolean not is the " { $link not } " word."
185 $nl
186 "Due to the two's complement representation of signed integers, the following two lines are equivalent:" { $code "bitnot" "neg 1 -" } } ;
187
188 HELP: bit?
189 { $values { "x" integer } { "n" integer } { "?" boolean } }
190 { $description "Tests if the " { $snippet "n" } "th bit of " { $snippet "x" } " is set." }
191 { $examples { $example "USING: math prettyprint ;" "0b101 2 bit? ." "t" } } ;
192
193 HELP: log2
194 { $values { "x" "a positive integer" } { "n" integer } }
195 { $description "Outputs the largest integer " { $snippet "n" } " such that " { $snippet "2^n" } " is less than or equal to " { $snippet "x" } "." }
196 { $errors "Throws an error if " { $snippet "x" } " is zero or negative." } ;
197
198 HELP: ?1+
199 { $values { "x" { $maybe number } } { "y" number } }
200 { $description "If the input is not " { $link f } ", adds one. Otherwise, outputs a " { $snippet "0" } "." } ;
201
202 HELP: sq
203 { $values { "x" number } { "y" number } }
204 { $description "Multiplies a number by itself." } ;
205
206 HELP: neg
207 { $values { "x" number } { "-x" number } }
208 { $description "Computes a number's additive inverse." } ;
209
210 HELP: recip
211 { $values { "x" number } { "y" number } }
212 { $description "Computes a number's multiplicative inverse." }
213 { $errors "Throws an error if " { $snippet "x" } " is the integer 0." } ;
214
215 HELP: rem
216 { $values { "x" rational } { "y" rational } { "z" rational } }
217 { $description
218     "Computes the remainder of dividing " { $snippet "x" } " by " { $snippet "y" } ", with the remainder always positive or zero."
219     { $list
220         "Given fixnums, always yields a fixnum."
221         "Given bignums, always yields a bignum."
222         "Given rationals, always yields a rational."
223     }
224 }
225 { $see-also "division-by-zero" mod } ;
226
227 HELP: sgn
228 { $values { "x" real } { "n" "-1, 0 or 1" } }
229 { $description
230     "Outputs one of the following:"
231     { $list
232         { "-1 if " { $snippet "x" } " is negative" }
233         { "0 if " { $snippet "x" } " is equal to 0" }
234         { "1 if " { $snippet "x" } " is positive" }
235     }
236 } ;
237
238 HELP: 2/
239 { $values { "x" integer } { "y" integer } }
240 { $description "Shifts " { $snippet "x" } " to the right by one bit." }
241 { $examples
242     { $example "USING: math prettyprint ;" "14 2/ ." "7" }
243     { $example "USING: math prettyprint ;" "17 2/ ." "8" }
244     { $example "USING: math prettyprint ;" "-17 2/ ." "-9" }
245 }
246 { $notes "This word is not equivalent to " { $snippet "2 /" } " or " { $snippet "2 /i" } "; the name is historic and originates from the Forth programming language." } ;
247
248 HELP: 2^
249 { $values { "n" "a positive integer" } { "2^n" "a positive integer" } }
250 { $description "Computes two to the power of " { $snippet "n" } ". This word will only give correct results if " { $snippet "n" } " is greater than zero; for the general case, use " { $snippet "2 swap ^" } "." } ;
251
252 HELP: zero?
253 { $values { "x" number } { "?" boolean } }
254 { $description "Tests if the number is equal to zero." } ;
255
256 HELP: if-zero
257 { $values { "n" number } { "quot1" quotation } { "quot2" quotation } }
258 { $description "Makes an implicit check if the number is zero. A zero is dropped and " { $snippet "quot1" } " is called. Otherwise, if the number is not zero, " { $snippet "quot2" } " is called on it." }
259 { $example
260     "USING: kernel math prettyprint sequences ;"
261     "3 [ \"zero\" ] [ sq ] if-zero ."
262     "9"
263 } ;
264
265 HELP: when-zero
266 { $values
267      { "n" number } { "quot" "the first quotation of an " { $link if-zero } } }
268 { $description "Makes an implicit check if the number is zero. A zero is dropped and the " { $snippet "quot" } " is called." }
269 { $examples "This word is equivalent to " { $link if-zero } " with an empty second quotation:"
270     { $example
271     "USING: math prettyprint ;"
272     "0 [ 4 ] [ ] if-zero ."
273     "4"
274     }
275     { $example
276     "USING: math prettyprint ;"
277     "0 [ 4 ] when-zero ."
278     "4"
279     }
280 } ;
281
282 HELP: unless-zero
283 { $values
284      { "n" number } { "quot" "the second quotation of an " { $link if-empty } } }
285 { $description "Makes an implicit check if the number is zero. A zero is dropped. Otherwise, the " { $snippet "quot" } " is called on the number." }
286 { $examples "This word is equivalent to " { $link if-zero } " with an empty first quotation:"
287     { $example
288     "USING: sequences math prettyprint ;"
289     "3 [ ] [ sq ] if-zero ."
290     "9"
291     }
292     { $example
293     "USING: sequences math prettyprint ;"
294     "3 [ sq ] unless-zero ."
295     "9"
296     }
297 } ;
298
299 HELP: times
300 { $values { "n" integer } { "quot" quotation } }
301 { $description "Calls the quotation " { $snippet "n" } " times." }
302 { $notes "If you need to pass the current index to the quotation, use " { $link each } "." }
303 { $examples
304     { $example "USING: io math ;" "3 [ \"Hi\" print ] times" "Hi\nHi\nHi" }
305 } ;
306
307 HELP: fp-bitwise=
308 { $values
309     { "x" float } { "y" float }
310     { "?" boolean }
311 }
312 { $description "Compares two floating point numbers for bit equality." }
313 { $notes "Unlike " { $link = } " or " { $link number= } ", this word will consider NaNs with equal payloads to be equal, and positive zero and negative zero to be not equal." }
314 { $examples
315     "Not-a-number equality:"
316     { $example
317         "USING: kernel math prettyprint ;"
318         "0.0 0.0 / dup number= ."
319         "f"
320     }
321     { $example
322         "USING: kernel math prettyprint ;"
323         "0.0 0.0 / dup fp-bitwise= ."
324         "t"
325     }
326     "Signed zero equality:"
327     { $example
328         "USING: math prettyprint ;"
329         "-0.0 0.0 fp-bitwise= ."
330         "f"
331     }
332     { $example
333         "USING: math prettyprint ;"
334         "-0.0 0.0 number= ."
335         "t"
336     }
337 } ;
338
339 HELP: fp-special?
340 { $values { "x" real } { "?" boolean } }
341 { $description "Tests if " { $snippet "x" } " is an IEEE special value (Not-a-Number or Infinity). While " { $snippet "x" } " can be any real number, this word will only ever yield true if " { $snippet "x" } " is a " { $link float } "." } ;
342
343 HELP: fp-nan?
344 { $values { "x" real } { "?" boolean } }
345 { $description "Tests if " { $snippet "x" } " is an IEEE Not-a-Number value. While " { $snippet "x" } " can be any real number, this word will only ever yield true if " { $snippet "x" } " is a " { $link float } "." } ;
346
347 HELP: fp-qnan?
348 { $values { "x" real } { "?" boolean } }
349 { $description "Tests if " { $snippet "x" } " is an IEEE Quiet Not-a-Number value. While " { $snippet "x" } " can be any real number, this word will only ever yield true if " { $snippet "x" } " is a " { $link float } "." } ;
350
351 HELP: fp-snan?
352 { $values { "x" real } { "?" boolean } }
353 { $description "Tests if " { $snippet "x" } " is an IEEE Signaling Not-a-Number value. While " { $snippet "x" } " can be any real number, this word will only ever yield true if " { $snippet "x" } " is a " { $link float } "." } ;
354
355 HELP: fp-infinity?
356 { $values { "x" real } { "?" boolean } }
357 { $description "Tests if " { $snippet "x" } " is an IEEE Infinity value. While " { $snippet "x" } " can be any real number, this word will only ever yield true if " { $snippet "x" } " is a " { $link float } "." }
358 { $examples
359     { $example "USING: math prettyprint ;" "1/0. fp-infinity? ." "t" }
360     { $example "USING: io kernel math ;" "-1/0. [ fp-infinity? ] [ 0 < ] bi and [ \"negative infinity\" print ] when" "negative infinity" }
361 } ;
362
363 HELP: fp-sign
364 { $values { "x" float } { "?" boolean } }
365 { $description "Outputs the sign bit of " { $snippet "x" } ". For ordered non-zero values, this is equivalent to calling " { $snippet "0 <" } ". For zero values, this outputs the zero's sign bit." } ;
366
367 HELP: fp-nan-payload
368 { $values { "x" real } { "bits" integer } }
369 { $description "If " { $snippet "x" } " is an IEEE Not-a-Number value, returns the payload encoded in the value. Returns " { $link f } " if " { $snippet "x" } " is not a " { $link float } "." } ;
370
371 HELP: <fp-nan>
372 { $values { "payload" integer } { "nan" float } }
373 { $description "Constructs an IEEE Not-a-Number value with a payload of " { $snippet "payload" } "." }
374 { $notes "A " { $snippet "payload" } " of " { $snippet "0" } " will construct an Infinity value." } ;
375
376 { fp-special? fp-nan? fp-qnan? fp-snan? fp-infinity? fp-nan-payload <fp-nan> } related-words
377
378 HELP: next-float
379 { $values { "m" float } { "n" float } }
380 { $description "Returns the least representable " { $link float } " value greater than " { $snippet "m" } ", or in the case of " { $snippet "-0.0" } ", returns " { $snippet "+0.0" } "." } ;
381
382 HELP: prev-float
383 { $values { "m" float } { "n" float } }
384 { $description "Returns the greatest representable " { $link float } " value less than " { $snippet "m" } ", or in the case of " { $snippet "+0.0" } ", returns " { $snippet "-0.0" } "." } ;
385
386 { next-float prev-float } related-words
387
388 HELP: real-part
389 { $values { "z" number } { "x" real } }
390 { $description "Outputs the real part of a complex number. This acts as the identity on real numbers." }
391 { $examples { $example "USING: math prettyprint ;" "C{ 1 2 } real-part ." "1" } } ;
392
393 HELP: imaginary-part
394 { $values { "z" number } { "y" real } }
395 { $description "Outputs the imaginary part of a complex number. This outputs zero for real numbers." }
396 { $examples
397     { $example "USING: math prettyprint ;" "C{ 1 2 } imaginary-part ." "2" }
398     { $example "USING: math prettyprint ;" "3 imaginary-part ." "0" }
399 } ;
400
401 HELP: real
402 { $class-description "The class of real numbers, which is a disjoint union of rationals and floats." } ;
403
404 HELP: number
405 { $class-description "The class of numbers." } ;
406
407 HELP: next-power-of-2
408 { $values { "m" "a non-negative integer" } { "n" integer } }
409 { $description "Outputs the smallest power of 2 greater than or equal to " { $snippet "m" } ". The output value is always at least 2." } ;
410
411 HELP: power-of-2?
412 { $values { "n" integer } { "?" boolean } }
413 { $description "Tests if " { $snippet "n" } " is a power of 2." } ;
414
415 HELP: each-integer
416 { $values { "n" integer } { "quot" { $quotation ( ... i -- ... ) } } }
417 { $description "Applies the quotation to each integer from 0 up to " { $snippet "n" } ", excluding " { $snippet "n" } "." }
418 { $notes "This word is used to implement " { $link each } "." } ;
419
420 HELP: all-integers?
421 { $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "?" boolean } }
422 { $description "Applies the quotation to each integer from 0 up to " { $snippet "n" } ", excluding " { $snippet "n" } ". Iteration stops when the quotation outputs " { $link f } " or the end is reached. If the quotation yields a false value for some integer, this word outputs " { $link f } ". Otherwise, this word outputs " { $link t } "." }
423 { $notes "This word is used to implement " { $link all? } "." } ;
424
425 HELP: find-integer
426 { $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "i" { $maybe integer } } }
427 { $description "Applies the quotation to each integer from 0 up to " { $snippet "n" } ", excluding " { $snippet "n" } ". Iteration stops when the quotation outputs a true value or the end is reached. If the quotation yields a true value for some integer, this word outputs that integer. Otherwise, this word outputs " { $link f } "." }
428 { $notes "This word is used to implement " { $link find } "." } ;
429
430 HELP: find-last-integer
431 { $values { "n" integer } { "quot" { $quotation ( ... i -- ... ? ) } } { "i" { $maybe integer } } }
432 { $description "Applies the quotation to each integer from " { $snippet "n" } " down to 0, inclusive. Iteration stops when the quotation outputs a true value or 0 is reached. If the quotation yields a true value for some integer, the word outputs that integer. Otherwise, the word outputs " { $link f } "." }
433 { $notes "This word is used to implement " { $link find-last } "." } ;
434
435 ARTICLE: "division-by-zero" "Division by zero"
436 "Behavior of division operations when a denominator of zero is used depends on the data types in question, as well as the platform being used."
437 $nl
438 "Floating point division only throws an error if the appropriate traps are enabled in the floating point environment. If traps are disabled, a Not-a-number value or an infinity is output, depending on whether the numerator is zero or non-zero."
439 $nl
440 "Floating point traps are disabled by default and the " { $vocab-link "math.floats.env" } " vocabulary provides words to enable them. Floating point division is performed by " { $link / } ", " { $link /f } " or " { $link mod } " if at least one of the two inputs is a float. Floating point division is always performed by " { $link /f } "."
441 $nl
442 "The behavior of integer division is hardware specific. On x86 processors, " { $link /i } " and " { $link mod } " raise an error if both inputs are integers and the denominator is zero. On PowerPC, integer division by zero yields a result of zero."
443 $nl
444 "The " { $link / } " word, when given integer arguments, implements a much more expensive division algorithm which always yields an exact rational answer, and this word always tests for division by zero explicitly." ;
445
446 ARTICLE: "number-protocol" "Number protocol"
447 "Math operations obey certain numerical upgrade rules. If one of the inputs is a bignum and the other is a fixnum, the latter is first coerced to a bignum; if one of the inputs is a float, the other is coerced to a float."
448 $nl
449 "Two examples where you should note the types of the inputs and outputs:"
450 { $example "USE: classes" "3 >fixnum 6 >bignum * class-of ." "bignum" }
451 { $example "1/2 2.0 + ." "2.5" }
452 "The following usual operations are supported by all numbers."
453 { $subsections
454     +
455     -
456     *
457     /
458 }
459 "Non-commutative operations take operands from the stack in the natural order; " { $snippet "6 2 /" } " divides 6 by 2."
460 { $subsections "division-by-zero" }
461 "Real numbers (but not complex numbers) can be ordered:"
462 { $subsections
463     <
464     <=
465     >
466     >=
467 }
468 "Numbers can be compared for equality using " { $link = } ", or a less precise test which disregards types:"
469 { $subsections number= }
470 { $see-also "math.floats.compare" } ;
471
472 ARTICLE: "modular-arithmetic" "Modular arithmetic"
473 { $subsections
474     mod
475     rem
476     /mod
477     /i
478 }
479 { $see-also "integer-functions" } ;
480
481 ARTICLE: "bitwise-arithmetic" "Bitwise arithmetic"
482 "There are two ways of looking at an integer -- as an abstract mathematical entity, or as a string of bits. The latter representation motivates " { $emphasis "bitwise operations" } "."
483 { $subsections
484     bitand
485     bitor
486     bitxor
487     bitnot
488     shift
489     2/
490     2^
491     bit?
492 }
493 "Advanced topics:"
494 { $subsections
495     "math.bitwise"
496     "math.bits"
497 }
498 { $see-also "booleans" } ;
499
500 ARTICLE: "arithmetic" "Arithmetic"
501 "Factor attempts to preserve natural mathematical semantics for numbers. Multiplying two large integers never results in overflow, and dividing two integers yields an exact ratio. Floating point numbers are also supported, along with complex numbers."
502 $nl
503 "Math words are in the " { $vocab-link "math" } " vocabulary. Implementation details are in the " { $vocab-link "math.private" } " vocabulary."
504 { $subsections
505     "number-protocol"
506     "modular-arithmetic"
507     "bitwise-arithmetic"
508 }
509 { $see-also "integers" "rationals" "floats" "complex-numbers" } ;
510
511 ABOUT: "arithmetic"
512