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