1 USING: help.markup help.syntax math math.private ;
4 ARTICLE: "integers" "Integers"
5 { $subsections integer }
6 "Integers come in two varieties -- fixnums and bignums. Fixnums fit in a machine word and are faster to manipulate; if the result of a fixnum operation is too large to fit in a fixnum, the result is upgraded to a bignum. Here is an example where two fixnums are multiplied yielding a bignum:"
7 { $example "USE: classes" "67108864 class-of ." "fixnum" }
8 { $example "USE: classes" "128 class-of ." "fixnum" }
9 { $example "134217728 128 * ." "17179869184" }
10 { $example "USE: classes" "1 128 shift class-of ." "bignum" }
11 "Integers can be entered using a different base; see " { $link "syntax-numbers" } "."
13 "Integers can be tested for, and real numbers can be converted to integers:"
21 { $see-also "prettyprint-numbers" "modular-arithmetic" "bitwise-arithmetic" "integer-functions" "syntax-integers" } ;
26 { $class-description "The class of fixnums, which are fixed-width integers small enough to fit in a machine cell. Because they are not heap-allocated, fixnums do not have object identity. Equality of tagged pointer bit patterns is actually " { $emphasis "value" } " equality for fixnums." } ;
29 { $values { "x" real } { "n" fixnum } }
30 { $description "Converts a real number to a fixnum, with a possible loss of precision and overflow." } ;
33 { $class-description "The class of bignums, which are heap-allocated arbitrary-precision integers." } ;
36 { $values { "x" real } { "n" bignum } }
37 { $description "Converts a real number to a bignum, with a possible loss of precision." } ;
40 { $values { "x" real } { "n" bignum } }
41 { $description "Converts a real number to an integer, with a possible loss of precision." } ;
44 { $class-description "The class of integers, which is a disjoint union of fixnums and bignums." } ;
47 { $values { "n" integer } { "?" "a boolean" } }
48 { $description "Tests if an integer is even." } ;
51 { $values { "n" integer } { "?" "a boolean" } }
52 { $description "Tests if an integer is odd." } ;
56 { $values { "x" fixnum } { "y" fixnum } { "z" integer } }
57 { $description "Primitive version of " { $link + } ". The result may overflow to a bignum." }
58 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link + } " instead." } ;
61 { $values { "x" fixnum } { "y" fixnum } { "z" integer } }
62 { $description "Primitive version of " { $link - } ". The result may overflow to a bignum." }
63 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link - } " instead." } ;
66 { $values { "x" fixnum } { "y" fixnum } { "z" integer } }
67 { $description "Primitive version of " { $link * } ". The result may overflow to a bignum." }
68 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link * } " instead." } ;
71 { $values { "x" fixnum } { "y" fixnum } { "z" integer } }
72 { $description "Primitive version of " { $link /i } ". The result may overflow to a bignum." }
73 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link /i } " instead." } ;
76 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
77 { $description "Primitive version of " { $link mod } ". The result always fits in a fixnum." }
78 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link mod } " instead." } ;
81 { $values { "x" fixnum } { "y" fixnum } { "z" integer } { "w" fixnum } }
82 { $description "Primitive version of " { $link /mod } ". The result may overflow to a bignum." }
83 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link /mod } " instead." } ;
86 { $values { "x" fixnum } { "y" fixnum } { "?" "a boolean" } }
87 { $description "Primitive version of " { $link < } ". The result may overflow to a bignum." }
88 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link < } " instead." } ;
91 { $values { "x" fixnum } { "y" fixnum } { "z" integer } }
92 { $description "Primitive version of " { $link <= } ". The result may overflow to a bignum." }
93 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link <= } " instead." } ;
96 { $values { "x" fixnum } { "y" fixnum } { "?" "a boolean" } }
97 { $description "Primitive version of " { $link > } ". The result may overflow to a bignum." }
98 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link > } " instead." } ;
101 { $values { "x" fixnum } { "y" fixnum } { "?" "a boolean" } }
102 { $description "Primitive version of " { $link >= } ". The result may overflow to a bignum." }
103 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link >= } " instead." } ;
106 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
107 { $description "Primitive version of " { $link bitand } ". The result always fits in a fixnum." }
108 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitand } " instead." } ;
111 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
112 { $description "Primitive version of " { $link bitor } ". The result always fits in a fixnum." }
113 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitor } " instead." } ;
116 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
117 { $description "Primitive version of " { $link bitxor } ". The result always fits in a fixnum." }
118 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitxor } " instead." } ;
121 { $values { "x" fixnum } { "y" fixnum } }
122 { $description "Primitive version of " { $link bitnot } ". The result always fits in a fixnum." }
123 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitnot } " instead." } ;
126 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
127 { $description "Primitive version of " { $link shift } ". The result may overflow to a bignum." }
128 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link shift } " instead." } ;
130 HELP: fixnum-shift-fast
131 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
132 { $description "Primitive version of " { $link shift } ". Unlike " { $link fixnum-shift } ", does not perform an overflow check, so the result may be incorrect." }
133 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link shift } " instead." } ;
136 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
137 { $description "Primitive version of " { $link + } ". Unlike " { $link fixnum+ } ", does not perform an overflow check, so the result may be incorrect." }
138 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link + } " instead." } ;
141 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
142 { $description "Primitive version of " { $link - } ". Unlike " { $link fixnum- } ", does not perform an overflow check, so the result may be incorrect." }
143 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link - } " instead." } ;
146 { $values { "x" fixnum } { "y" fixnum } { "z" fixnum } }
147 { $description "Primitive version of " { $link * } ". Unlike " { $link fixnum* } ", does not perform an overflow check, so the result may be incorrect." }
148 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link * } " instead." } ;
151 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
152 { $description "Primitive version of " { $link + } "." }
153 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link + } " instead." } ;
156 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
157 { $description "Primitive version of " { $link - } "." }
158 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link - } " instead." } ;
161 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
162 { $description "Primitive version of " { $link * } "." }
163 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link * } " instead." } ;
166 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
167 { $description "Primitive version of " { $link /i } "." }
168 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link /i } " instead." } ;
171 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
172 { $description "Primitive version of " { $link mod } "." }
173 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link mod } " instead." } ;
176 { $values { "x" bignum } { "y" bignum } { "z" bignum } { "w" bignum } }
177 { $description "Primitive version of " { $link /mod } "." }
178 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link /mod } " instead." } ;
181 { $values { "x" bignum } { "y" bignum } { "?" "a boolean" } }
182 { $description "Primitive version of " { $link < } "." }
183 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link < } " instead." } ;
186 { $values { "x" bignum } { "y" bignum } { "?" "a boolean" } }
187 { $description "Primitive version of " { $link <= } "." }
188 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link <= } " instead." } ;
191 { $values { "x" bignum } { "y" bignum } { "?" "a boolean" } }
192 { $description "Primitive version of " { $link > } "." }
193 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link > } " instead." } ;
196 { $values { "x" bignum } { "y" bignum } { "?" "a boolean" } }
197 { $description "Primitive version of " { $link >= } "." }
198 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link >= } " instead." } ;
201 { $values { "x" bignum } { "y" bignum } { "?" "a boolean" } }
202 { $description "Primitive version of " { $link number= } "." }
203 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link number= } " instead." } ;
206 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
207 { $description "Primitive version of " { $link bitand } "." }
208 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitand } " instead." } ;
211 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
212 { $description "Primitive version of " { $link bitor } "." }
213 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitor } " instead." } ;
216 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
217 { $description "Primitive version of " { $link bitxor } "." }
218 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitxor } " instead." } ;
221 { $values { "x" bignum } { "y" bignum } }
222 { $description "Primitive version of " { $link bitnot } "." }
223 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link bitnot } " instead." } ;
226 { $values { "x" bignum } { "y" bignum } { "z" bignum } }
227 { $description "Primitive version of " { $link shift } "." }
228 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link shift } " instead." } ;