author | Claus Gittinger <cg@exept.de> |
Mon, 19 Aug 1996 09:58:23 +0200 | |
changeset 1635 | 60eb1c5a3855 |
parent 1628 | da30f2f41db7 |
child 1701 | 80d13adb2e77 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
202 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ArithmeticValue subclass:#Number |
|
973 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Magnitude-Numbers' |
|
1 | 18 |
! |
19 |
||
1557 | 20 |
!Number class methodsFor:'documentation'! |
88 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
202 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
88 | 36 |
documentation |
37 |
" |
|
38 |
abstract superclass for all kinds of numbers |
|
1295 | 39 |
|
40 |
[author:] |
|
41 |
Claus Gittinger |
|
1628 | 42 |
|
43 |
[see also:] |
|
44 |
Integer LargeInteger SmallInteger |
|
45 |
LimitedPrecisionReal Float ShortFloat |
|
88 | 46 |
" |
47 |
! ! |
|
1 | 48 |
|
1557 | 49 |
!Number class methodsFor:'instance creation'! |
1 | 50 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
51 |
readFrom:aStringOrStream onError:exceptionBlock |
1 | 52 |
"return the next Number from the (character-)stream aStream; |
202 | 53 |
skipping all whitespace first; return the value of exceptionBlock, |
54 |
if no number can be read." |
|
1 | 55 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
56 |
|str nextChar radix value negative signExp freakOut| |
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
57 |
|
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
58 |
str := aStringOrStream readStream. |
1 | 59 |
|
973 | 60 |
ErrorSignal handle:[:ex | |
61 |
^ exceptionBlock value |
|
339 | 62 |
] do:[ |
973 | 63 |
nextChar := str skipSeparators. |
64 |
nextChar isNil ifTrue:[^ exceptionBlock value]. |
|
3 | 65 |
|
973 | 66 |
freakOut := [^ exceptionBlock value]. |
339 | 67 |
|
973 | 68 |
(nextChar == $-) ifTrue:[ |
69 |
negative := true. |
|
70 |
nextChar := str nextPeek |
|
71 |
] ifFalse:[ |
|
72 |
negative := false. |
|
73 |
(nextChar == $+) ifTrue:[ |
|
74 |
nextChar := str nextPeek |
|
75 |
] |
|
76 |
]. |
|
77 |
nextChar isDigit ifFalse:[ |
|
78 |
^ exceptionBlock value. |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
79 |
"/ value := super readFrom:str. |
339 | 80 |
"/ negative ifTrue:[value := value negated]. |
81 |
"/ ^ value |
|
973 | 82 |
]. |
83 |
value := Integer readFrom:str radix:10 onError:freakOut. |
|
84 |
nextChar := str peek. |
|
85 |
((nextChar == $r) or:[ nextChar == $R]) ifTrue:[ |
|
86 |
str next. |
|
87 |
radix := value. |
|
88 |
value := Integer readFrom:str radix:radix onError:freakOut. |
|
89 |
] ifFalse:[ |
|
90 |
radix := 10 |
|
91 |
]. |
|
92 |
(nextChar == $.) ifTrue:[ |
|
93 |
nextChar := str nextPeek. |
|
94 |
(nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[ |
|
95 |
value := value asFloat |
|
96 |
+ (Number readMantissaFrom:str radix:radix). |
|
97 |
nextChar := str peek |
|
98 |
] |
|
99 |
]. |
|
100 |
((nextChar == $e) or:[nextChar == $E]) ifTrue:[ |
|
101 |
nextChar := str nextPeek. |
|
102 |
signExp := 1. |
|
103 |
(nextChar == $+) ifTrue:[ |
|
104 |
nextChar := str nextPeek |
|
105 |
] ifFalse:[ |
|
106 |
(nextChar == $-) ifTrue:[ |
|
107 |
nextChar := str nextPeek. |
|
108 |
signExp := -1 |
|
109 |
] |
|
110 |
]. |
|
111 |
(nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[ |
|
112 |
value := value asFloat |
|
113 |
* (10.0 raisedToInteger: |
|
114 |
((Integer readFrom:str radix:radix onError:freakOut) * signExp)) |
|
115 |
] |
|
116 |
]. |
|
117 |
negative ifTrue:[ |
|
118 |
^ value negated |
|
119 |
]. |
|
120 |
^ value |
|
339 | 121 |
] |
1 | 122 |
|
329 | 123 |
" |
124 |
Number readFrom:(ReadStream on:'54.32e-01') |
|
125 |
Number readFrom:(ReadStream on:'12345678901234567890') |
|
126 |
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
127 |
Number readFrom:'16rAAAAFFFFAAAAFFFF' |
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
128 |
Number readFrom:'0.000001' |
329 | 129 |
'+00000123.45' asNumber |
130 |
" |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
131 |
|
973 | 132 |
"Modified: 20.2.1996 / 20:24:19 / cg" |
296 | 133 |
! |
134 |
||
135 |
readSmalltalkSyntaxFrom:aStream |
|
136 |
"ST-80 compatibility (thanks to a note from alpha testers) |
|
137 |
read and return the next Number in smalltalk syntax from the |
|
329 | 138 |
(character-)stream aStream." |
139 |
||
140 |
^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream. |
|
296 | 141 |
|
329 | 142 |
" |
143 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01') |
|
144 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890') |
|
145 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
|
146 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') |
|
147 |
Number readFrom:(ReadStream on:'(1/10)') |
|
148 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45') |
|
149 |
Number readFrom:(ReadStream on:'+00000123.45') |
|
150 |
" |
|
1 | 151 |
! ! |
701 | 152 |
|
1557 | 153 |
!Number class methodsFor:'error reporting'! |
701 | 154 |
|
155 |
raise:aSignalSymbol receiver:someNumber selector:sel arg:arg errorString:text |
|
156 |
"ST-80 compatible signal raising. Provided for PD numeric classes" |
|
157 |
||
158 |
|msg| |
|
159 |
||
160 |
msg := MessageSend |
|
161 |
receiver:someNumber |
|
162 |
selector:sel |
|
163 |
arguments:(Array with:arg). |
|
164 |
^ (self perform:aSignalSymbol) |
|
165 |
raiseRequestWith:msg |
|
166 |
errorString:text |
|
167 |
in:thisContext sender |
|
168 |
||
169 |
" |
|
170 |
Number raise:#domainErrorSignal |
|
171 |
receiver:1.0 |
|
172 |
selector:#sin |
|
173 |
arg:nil |
|
174 |
errorString:'foo bar test' |
|
175 |
" |
|
176 |
! |
|
177 |
||
178 |
raise:aSignalSymbol receiver:someNumber selector:sel errorString:text |
|
179 |
"ST-80 compatible signal raising. Provided for PD numeric classes" |
|
180 |
||
181 |
|msg| |
|
182 |
||
183 |
msg := MessageSend |
|
184 |
receiver:someNumber |
|
185 |
selector:sel |
|
186 |
arguments:#(). |
|
187 |
^ (self perform:aSignalSymbol) |
|
188 |
raiseRequestWith:msg |
|
189 |
errorString:text |
|
190 |
in:thisContext sender |
|
191 |
||
192 |
" |
|
193 |
Number raise:#domainErrorSignal |
|
194 |
receiver:1.0 |
|
195 |
selector:#foo |
|
196 |
errorString:'foo bar test' |
|
197 |
" |
|
198 |
! ! |
|
199 |
||
1557 | 200 |
!Number class methodsFor:'private'! |
701 | 201 |
|
202 |
readMantissaFrom:aStream radix:radix |
|
203 |
"helper for readFrom: - |
|
204 |
return the mantissa from the (character-)stream aStream; |
|
205 |
no whitespace-skipping; error if no number available" |
|
206 |
||
207 |
|nextChar value factor| |
|
208 |
||
209 |
value := 0.0. |
|
210 |
factor := 1.0 / radix. |
|
211 |
nextChar := aStream peek. |
|
212 |
[nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[ |
|
213 |
value := value + (nextChar digitValue * factor). |
|
214 |
factor := factor / radix. |
|
215 |
nextChar := aStream nextPeek |
|
216 |
]. |
|
217 |
^ value |
|
218 |
! ! |
|
219 |
||
220 |
!Number methodsFor:'coercing'! |
|
221 |
||
222 |
coerce:aNumber |
|
223 |
"return aNumber converted into receivers type" |
|
224 |
||
225 |
^ self subclassResponsibility |
|
226 |
! |
|
227 |
||
228 |
generality |
|
229 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
230 |
||
231 |
^ 40 |
|
232 |
! ! |
|
233 |
||
234 |
!Number methodsFor:'converting'! |
|
235 |
||
236 |
@ aNumber |
|
237 |
"return a Point with the receiver as x-coordinate and the argument |
|
238 |
as y-coordinate" |
|
239 |
||
240 |
%{ /* NOCONTEXT */ |
|
241 |
||
242 |
/* |
|
243 |
* I cannot tell if this special code is worth anything |
|
244 |
*/ |
|
835 | 245 |
if (__CanDoQuickNew(sizeof(struct __point))) { |
701 | 246 |
OBJ newPoint; |
247 |
int spc; |
|
248 |
||
835 | 249 |
__qCheckedAlignedNew(newPoint, sizeof(struct __point)); |
1133 | 250 |
__InstPtr(newPoint)->o_class = @global(Point); |
251 |
__PointInstPtr(newPoint)->p_x = self; |
|
252 |
__PointInstPtr(newPoint)->p_y = aNumber; |
|
701 | 253 |
if (! __bothSmallInteger(self, aNumber)) { |
254 |
spc = __qSpace(newPoint); |
|
255 |
__STORE_SPC(newPoint, aNumber, spc); |
|
256 |
__STORE_SPC(newPoint, self, spc); |
|
257 |
} |
|
258 |
RETURN ( newPoint ); |
|
259 |
} |
|
260 |
%} |
|
261 |
. |
|
262 |
^ Point x:self y:aNumber |
|
263 |
! |
|
264 |
||
265 |
asPoint |
|
266 |
"return a new Point with the receiver as all coordinates; |
|
267 |
often used to supply the same value in two dimensions, as with |
|
268 |
symmetrical gridding or scaling." |
|
269 |
||
270 |
%{ /* NOCONTEXT */ |
|
271 |
||
835 | 272 |
if (__CanDoQuickNew(sizeof(struct __point))) { |
701 | 273 |
OBJ newPoint; |
274 |
||
835 | 275 |
__qCheckedAlignedNew(newPoint, sizeof(struct __point)); |
1133 | 276 |
__InstPtr(newPoint)->o_class = @global(Point); |
277 |
__PointInstPtr(newPoint)->p_x = self; |
|
278 |
__PointInstPtr(newPoint)->p_y = self; |
|
701 | 279 |
__STORE(newPoint, self); |
280 |
RETURN ( newPoint ); |
|
281 |
} |
|
282 |
%}. |
|
283 |
^ Point x:self y:self |
|
284 |
! |
|
285 |
||
286 |
degreesToRadians |
|
287 |
"interpreting the receiver as radians, return the degrees" |
|
288 |
||
289 |
^ (self * (Float pi)) / 180.0 |
|
290 |
! |
|
291 |
||
292 |
literalArrayEncoding |
|
1245 | 293 |
"encode myself as an array literal, from which a copy of the receiver |
294 |
can be reconstructed with #decodeAsLiteralArray." |
|
701 | 295 |
|
296 |
^ self |
|
297 |
||
298 |
"Modified: 1.9.1995 / 02:25:26 / claus" |
|
1245 | 299 |
"Modified: 22.4.1996 / 13:00:27 / cg" |
701 | 300 |
! |
301 |
||
302 |
radiansToDegrees |
|
303 |
"interpreting the receiver as degrees, return the radians" |
|
304 |
||
305 |
^ (self * 180.0) / (Float pi) |
|
306 |
! ! |
|
307 |
||
308 |
!Number methodsFor:'intervals'! |
|
309 |
||
310 |
to:stop |
|
311 |
"return an interval from receiver up to the argument, incrementing by 1" |
|
312 |
||
313 |
^ Interval from:self to:stop |
|
314 |
! |
|
315 |
||
316 |
to:stop by:step |
|
317 |
"return an interval from receiver up to the argument, incrementing by step" |
|
318 |
||
319 |
^ Interval from:self to:stop by:step |
|
320 |
! ! |
|
321 |
||
322 |
!Number methodsFor:'iteration'! |
|
323 |
||
324 |
timesRepeat:aBlock |
|
325 |
"evaluate the argument, aBlock self times" |
|
326 |
||
327 |
|count| |
|
328 |
||
329 |
count := self. |
|
330 |
[count > 0] whileTrue:[ |
|
331 |
aBlock value. |
|
332 |
count := count - 1 |
|
333 |
] |
|
334 |
! |
|
335 |
||
336 |
to:stop by:incr do:aBlock |
|
337 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
|
338 |
by step, evaluate aBlock passing the element as argument." |
|
339 |
||
340 |
|tmp| |
|
341 |
||
342 |
tmp := self. |
|
343 |
(incr > 0) ifTrue:[ |
|
344 |
[tmp <= stop] whileTrue:[ |
|
345 |
aBlock value:tmp. |
|
346 |
tmp := tmp+incr |
|
347 |
] |
|
348 |
] ifFalse:[ |
|
349 |
[tmp >= stop] whileTrue:[ |
|
350 |
aBlock value:tmp. |
|
351 |
tmp := tmp+incr |
|
352 |
] |
|
353 |
] |
|
354 |
! |
|
355 |
||
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
356 |
to:stop by:incr doWithBreak:aBlock |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
357 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
358 |
by step, evaluate aBlock passing the element as argument. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
359 |
Pass a break argument, to allow for premature exit of the loop." |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
360 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
361 |
|tmp break| |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
362 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
363 |
break := [^ self]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
364 |
tmp := self. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
365 |
(incr > 0) ifTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
366 |
[tmp <= stop] whileTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
367 |
aBlock value:tmp value:break. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
368 |
tmp := tmp+incr |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
369 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
370 |
] ifFalse:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
371 |
[tmp >= stop] whileTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
372 |
aBlock value:tmp value:break. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
373 |
tmp := tmp+incr |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
374 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
375 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
376 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
377 |
" |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
378 |
1 to:100 by:5 doWithBreak:[:index :break | |
1422 | 379 |
Transcript showCR:index printString. |
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
380 |
index > 50 ifTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
381 |
break value |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
382 |
]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
383 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
384 |
" |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
385 |
! |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
386 |
|
701 | 387 |
to:stop do:aBlock |
388 |
"For each element of the interval from the receiver up to the argument stop, |
|
389 |
evaluate aBlock, passing the number as argument." |
|
390 |
||
391 |
|tmp| |
|
392 |
||
393 |
tmp := self. |
|
394 |
[tmp <= stop] whileTrue:[ |
|
395 |
aBlock value:tmp. |
|
396 |
tmp := tmp+1 |
|
397 |
] |
|
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
398 |
! |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
399 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
400 |
to:stop doWithBreak:aBlock |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
401 |
"For each element of the interval from the receiver up to the argument stop, |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
402 |
evaluate aBlock, passing the number as argument. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
403 |
Pass a break argument, to allow for premature exit of the loop." |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
404 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
405 |
|tmp break| |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
406 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
407 |
break := [^ self]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
408 |
tmp := self. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
409 |
[tmp <= stop] whileTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
410 |
aBlock value:tmp value:break. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
411 |
tmp := tmp+1 |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
412 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
413 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
414 |
" |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
415 |
1 to:10 doWithBreak:[:index :break | |
1422 | 416 |
Transcript showCR:index printString. |
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
417 |
index > 5 ifTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
418 |
break value |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
419 |
]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
420 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
421 |
" |
701 | 422 |
! ! |
423 |
||
424 |
!Number methodsFor:'printing & storing'! |
|
425 |
||
426 |
storeOn:aStream |
|
427 |
"append a string for storing the receiver onto the argument, |
|
428 |
aStream - since numbers are literals,they store as they print." |
|
429 |
||
430 |
^ self printOn:aStream |
|
431 |
! |
|
432 |
||
433 |
storeString |
|
434 |
"return a string for storing |
|
435 |
- since numbers are literals, they store as they print." |
|
436 |
||
437 |
^ self printString |
|
438 |
! ! |
|
439 |
||
440 |
!Number methodsFor:'testing'! |
|
441 |
||
442 |
isLiteral |
|
443 |
"return true, if the receiver can be used as a literal |
|
444 |
(i.e. can be used in constant arrays)" |
|
445 |
||
446 |
^ true |
|
447 |
! |
|
448 |
||
449 |
isNumber |
|
450 |
"return true, if the receiver is a kind of number" |
|
451 |
||
452 |
^ true |
|
453 |
! |
|
454 |
||
455 |
isZero |
|
1557 | 456 |
"return true, if the receiver is zero" |
457 |
||
701 | 458 |
^ self = 0 |
1557 | 459 |
|
460 |
"Modified: 18.7.1996 / 12:40:49 / cg" |
|
701 | 461 |
! ! |
462 |
||
1557 | 463 |
!Number class methodsFor:'documentation'! |
701 | 464 |
|
465 |
version |
|
1635
60eb1c5a3855
oops - checked in version with infinity stuff in it. Undone.
Claus Gittinger <cg@exept.de>
parents:
1628
diff
changeset
|
466 |
^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.35 1996-08-19 07:58:23 cg Exp $' |
701 | 467 |
! ! |