1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
|
5737
|
13 |
"{ Package: 'stx:libbasic' }"
|
|
14 |
|
1
|
15 |
ArrayedCollection variableFloatSubclass:#FloatArray
|
1263
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Collections-Arrayed'
|
1
|
20 |
!
|
|
21 |
|
88
|
22 |
!FloatArray class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
1
|
27 |
All Rights Reserved
|
|
28 |
|
88
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
1
|
37 |
|
88
|
38 |
documentation
|
|
39 |
"
|
|
40 |
FloatArrays store floats (and nothing else).
|
|
41 |
See documentation in DoubleArray for more information.
|
1263
|
42 |
|
4062
|
43 |
[memory requirements:]
|
|
44 |
OBJ-HEADER + (size * float-size)
|
|
45 |
|
1263
|
46 |
[See also:]
|
|
47 |
DoubleArray Array
|
1290
|
48 |
|
|
49 |
[author:]
|
|
50 |
Claus Gittinger
|
88
|
51 |
"
|
628
|
52 |
! !
|
|
53 |
|
5737
|
54 |
!FloatArray methodsFor:'arithmetic'!
|
|
55 |
|
|
56 |
* anObject
|
|
57 |
"return the product of the receiver and the argument.
|
|
58 |
The argument may either be a scalar or another vector"
|
|
59 |
|
|
60 |
^ self clone *= anObject
|
|
61 |
|
|
62 |
"
|
|
63 |
#(1 2 3 4) asFloatArray * 3
|
|
64 |
#(1 2 3 4) asFloatArray * #(1 2 3 4) asFloatArray
|
|
65 |
"
|
|
66 |
!
|
|
67 |
|
|
68 |
*= anObject
|
|
69 |
"multiply the argument into the receiver (destructive).
|
|
70 |
The argument may either be a scalar or another vector"
|
|
71 |
|
|
72 |
^ anObject isNumber
|
|
73 |
ifTrue:[self primMulScalar: anObject asFloat]
|
|
74 |
ifFalse:[self primMulArray: anObject]
|
|
75 |
|
|
76 |
"
|
|
77 |
|f|
|
|
78 |
|
|
79 |
f := #(1 2 3 4) asFloatArray.
|
|
80 |
f *= 3.
|
|
81 |
f
|
|
82 |
"
|
|
83 |
"
|
|
84 |
|f|
|
|
85 |
|
|
86 |
f := #(1 2 3 4) asFloatArray.
|
|
87 |
f *= #(1 2 3 4) asFloatArray.
|
|
88 |
f
|
|
89 |
"
|
|
90 |
!
|
|
91 |
|
|
92 |
+ anObject
|
|
93 |
"return the sum of the receiver and the argument.
|
|
94 |
The argument may either be a scalar or another vector"
|
|
95 |
|
|
96 |
^ self clone += anObject
|
|
97 |
|
|
98 |
"
|
|
99 |
#(1 2 3 4) asFloatArray + 3
|
|
100 |
#(1 2 3 4) asFloatArray + #(1 2 3 4) asFloatArray
|
|
101 |
"
|
|
102 |
!
|
|
103 |
|
|
104 |
+= anObject
|
|
105 |
"add the argument into the receiver (destructive).
|
|
106 |
The argument may either be a scalar or another vector"
|
|
107 |
|
|
108 |
^ anObject isNumber
|
|
109 |
ifTrue:[self primAddScalar: anObject asFloat]
|
|
110 |
ifFalse:[self primAddArray: anObject]
|
|
111 |
|
|
112 |
"
|
|
113 |
|f|
|
|
114 |
|
|
115 |
f := #(1 2 3 4) asFloatArray.
|
|
116 |
f += 3.
|
|
117 |
f
|
|
118 |
"
|
|
119 |
"
|
|
120 |
|f|
|
|
121 |
|
|
122 |
f := #(1 2 3 4) asFloatArray.
|
|
123 |
f += #(1 2 3 4) asFloatArray.
|
|
124 |
f
|
|
125 |
"
|
|
126 |
!
|
|
127 |
|
|
128 |
primAddArray: floatArray
|
|
129 |
"add the vector argument into the receiver (destructive).
|
|
130 |
The argument must be another vector"
|
|
131 |
|
|
132 |
%{
|
8913
|
133 |
if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
|
5737
|
134 |
&& __isFloats(floatArray)
|
8913
|
135 |
&& (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
|
5737
|
136 |
int _sz1 = __floatArraySize(self);
|
|
137 |
int _sz2 = __floatArraySize(floatArray);
|
|
138 |
int i;
|
|
139 |
float *_p1 = __FloatArrayInstPtr(self)->f_element;
|
|
140 |
float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
|
|
141 |
|
|
142 |
if (_sz2 >= _sz1) {
|
|
143 |
/* how about inline-mmx-asm for this ... */
|
|
144 |
for (i=0; i<_sz1; i++) {
|
|
145 |
_p1[i] += _p2[i];
|
|
146 |
}
|
|
147 |
}
|
|
148 |
RETURN (self);
|
|
149 |
}
|
|
150 |
%}.
|
|
151 |
1 to: self size do:[:i| self at: i put: (self at: i) + (floatArray at: i)].
|
|
152 |
|
|
153 |
"
|
|
154 |
|f1 f2|
|
|
155 |
|
|
156 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
157 |
f2 := FloatArray withAll:#(2 2 2 3 3).
|
|
158 |
f1 += f2.
|
|
159 |
f1
|
|
160 |
"
|
|
161 |
!
|
|
162 |
|
|
163 |
primAddScalar: aScalar
|
|
164 |
"add the scalar argument into the receiver (destructive)."
|
|
165 |
|
|
166 |
%{
|
8913
|
167 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
5737
|
168 |
int _sz1 = __floatArraySize(self);
|
|
169 |
int i;
|
|
170 |
float *_p1 = __FloatArrayInstPtr(self)->f_element;
|
|
171 |
float v;
|
|
172 |
|
|
173 |
if (__isFloat(aScalar)) {
|
|
174 |
v = (float)(__floatVal(aScalar));
|
|
175 |
} else if (__isShortFloat(aScalar)) {
|
|
176 |
v = __shortFloatVal(aScalar);
|
|
177 |
} else if (__isSmallInteger(aScalar)) {
|
|
178 |
v = (float)(__intVal(aScalar));
|
|
179 |
} else
|
|
180 |
goto badArg;
|
|
181 |
|
|
182 |
/* how about inline-mmx-asm for this ... */
|
|
183 |
for (i=0; i<_sz1; i++) {
|
|
184 |
_p1[i] += v;
|
|
185 |
}
|
|
186 |
RETURN (self);
|
|
187 |
}
|
|
188 |
badArg: ;
|
|
189 |
%}.
|
|
190 |
1 to: self size do:[:i| self at: i put: (self at: i) + aScalar].
|
|
191 |
|
|
192 |
"
|
|
193 |
|f1 f2|
|
|
194 |
|
|
195 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
196 |
f1 += 2.0.
|
|
197 |
Transcript showCR:f1.
|
|
198 |
f1 += 2.0 asShortFloat.
|
|
199 |
Transcript showCR:f1.
|
|
200 |
f1 += 2.
|
|
201 |
Transcript showCR:f1.
|
|
202 |
"
|
|
203 |
!
|
|
204 |
|
|
205 |
primMulArray: floatArray
|
|
206 |
"multiply the vector argument into the receiver (destructive).
|
|
207 |
The argument must be another vector"
|
|
208 |
|
|
209 |
%{
|
8913
|
210 |
if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
|
5737
|
211 |
&& __isFloats(floatArray)
|
8913
|
212 |
&& (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
|
5737
|
213 |
int _sz1 = __floatArraySize(self);
|
|
214 |
int _sz2 = __floatArraySize(floatArray);
|
|
215 |
int i;
|
|
216 |
float *_p1 = __FloatArrayInstPtr(self)->f_element;
|
|
217 |
float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
|
|
218 |
|
|
219 |
if (_sz2 >= _sz1) {
|
|
220 |
/* how about inline-mmx-asm for this ... */
|
|
221 |
for (i=0; i<_sz1; i++) {
|
|
222 |
_p1[i] *= _p2[i];
|
|
223 |
}
|
|
224 |
}
|
|
225 |
RETURN (self);
|
|
226 |
}
|
|
227 |
%}.
|
|
228 |
1 to: self size do:[:i| self at: i put: (self at: i) * (floatArray at: i)].
|
|
229 |
|
|
230 |
"
|
|
231 |
|f1 f2|
|
|
232 |
|
|
233 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
234 |
f2 := FloatArray withAll:#(2 2 2 3 3).
|
|
235 |
f1 *= f2.
|
|
236 |
f1
|
|
237 |
"
|
|
238 |
!
|
|
239 |
|
|
240 |
primMulScalar: aScalar
|
|
241 |
"multiply the scalar argument into the receiver (destructive)."
|
|
242 |
|
|
243 |
%{
|
8913
|
244 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
5737
|
245 |
int _sz1 = __floatArraySize(self);
|
|
246 |
int i;
|
|
247 |
float *_p1 = __FloatArrayInstPtr(self)->f_element;
|
|
248 |
float v;
|
|
249 |
|
|
250 |
if (__isFloat(aScalar)) {
|
|
251 |
v = (float)(__floatVal(aScalar));
|
|
252 |
} else if (__isShortFloat(aScalar)) {
|
|
253 |
v = __shortFloatVal(aScalar);
|
|
254 |
} else if (__isSmallInteger(aScalar)) {
|
|
255 |
v = (float)(__intVal(aScalar));
|
|
256 |
} else
|
|
257 |
goto badArg;
|
|
258 |
|
|
259 |
/* how about inline-mmx-asm for this ... */
|
|
260 |
for (i=0; i<_sz1; i++) {
|
|
261 |
_p1[i] *= v;
|
|
262 |
}
|
|
263 |
RETURN (self);
|
|
264 |
}
|
|
265 |
badArg: ;
|
|
266 |
%}.
|
|
267 |
1 to: self size do:[:i| self at: i put: (self at: i) * aScalar].
|
|
268 |
|
|
269 |
"
|
|
270 |
|f1 f2|
|
|
271 |
|
|
272 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
273 |
f1 *= 2.0.
|
|
274 |
Transcript showCR:f1.
|
|
275 |
f1 *= 2.0 asShortFloat.
|
|
276 |
Transcript showCR:f1.
|
|
277 |
f1 *= 2.
|
|
278 |
Transcript showCR:f1.
|
|
279 |
"
|
|
280 |
! !
|
|
281 |
|
|
282 |
!FloatArray methodsFor:'copying'!
|
|
283 |
|
|
284 |
clone
|
|
285 |
"return a copy of the receiver"
|
|
286 |
|
|
287 |
|newArr|
|
|
288 |
|
|
289 |
newArr := self class new:(self size).
|
|
290 |
%{
|
8913
|
291 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
5737
|
292 |
int _sz = __floatArraySize(self);
|
|
293 |
|
|
294 |
bcopy(__FloatArrayInstPtr(self)->f_element,
|
|
295 |
__FloatArrayInstPtr(newArr)->f_element,
|
|
296 |
sizeof(float) * _sz);
|
|
297 |
|
|
298 |
RETURN (newArr);
|
|
299 |
}
|
|
300 |
%}.
|
|
301 |
newArr replaceFrom:1 to:self size with:self startingAt:1.
|
|
302 |
^ newArr
|
|
303 |
|
|
304 |
"
|
|
305 |
|f1 f2|
|
|
306 |
|
|
307 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
308 |
f1 clone
|
|
309 |
"
|
|
310 |
!
|
|
311 |
|
|
312 |
copyFrom:start to:stop
|
|
313 |
"return a partial copy of the receiver"
|
|
314 |
|
|
315 |
%{
|
8913
|
316 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
5737
|
317 |
if (__bothSmallInteger(start, stop)) {
|
|
318 |
int __start = __intVal(start) - 1;
|
|
319 |
int __stop = __intVal(stop) - 1 ;
|
|
320 |
|
|
321 |
if (__stop >= __start) {
|
|
322 |
int __sz = __floatArraySize(self);
|
|
323 |
|
|
324 |
if (((unsigned)__start < __sz)
|
|
325 |
&& ((unsigned)__stop < __sz)) {
|
|
326 |
int __n = __stop - __start + 1;
|
|
327 |
OBJ __nObj;
|
|
328 |
|
|
329 |
__nObj = __STX___new(sizeof(struct __FloatArray) + (__n - 1) * sizeof(float));
|
|
330 |
if (__nObj != nil) {
|
|
331 |
__objPtr(__nObj)->o_class = __qClass(self);
|
|
332 |
__STORE(__nObj, __qClass(self));
|
|
333 |
bcopy(__FloatArrayInstPtr(self)->f_element + __start,
|
|
334 |
__FloatArrayInstPtr(__nObj)->f_element,
|
|
335 |
sizeof(float) * __n);
|
|
336 |
RETURN(__nObj);
|
|
337 |
}
|
|
338 |
}
|
|
339 |
}
|
|
340 |
}
|
|
341 |
}
|
|
342 |
%}.
|
|
343 |
^ super copyFrom:start to:stop
|
|
344 |
|
|
345 |
"
|
|
346 |
|f1 f2|
|
|
347 |
|
|
348 |
f1 := FloatArray withAll:#(1 2 3 4 5 6).
|
|
349 |
f2 := f1 copyFrom:2 to:4.
|
|
350 |
f2
|
|
351 |
"
|
|
352 |
!
|
|
353 |
|
|
354 |
replaceFrom:start to:stop with:aCollection startingAt:replStart
|
|
355 |
%{
|
8913
|
356 |
if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
|
5737
|
357 |
&& __isFloats(aCollection)
|
8913
|
358 |
&& (__ClassInstPtr(__qClass(aCollection))->c_ninstvars == __mkSmallInteger(0))) {
|
5737
|
359 |
if (__bothSmallInteger(start, stop)
|
|
360 |
&& __isSmallInteger(replStart)) {
|
|
361 |
int __start = __intVal(start) - 1;
|
|
362 |
int __stop = __intVal(stop) - 1 ;
|
|
363 |
int __replStart = __intVal(replStart) - 1 ;
|
|
364 |
|
|
365 |
if (__stop >= __start) {
|
|
366 |
int __sz = __floatArraySize(self);
|
|
367 |
int __otherSz = __floatArraySize(aCollection);
|
|
368 |
int __replStop = __replStart + (__stop-__start);
|
|
369 |
|
|
370 |
if (((unsigned)__start < __sz)
|
|
371 |
&& ((unsigned)__stop < __sz)
|
|
372 |
&& ((unsigned)__replStart < __otherSz)
|
|
373 |
&& ((unsigned)__replStop < __otherSz)) {
|
|
374 |
int __n = __stop - __start + 1;
|
|
375 |
|
5773
|
376 |
if (aCollection != self) {
|
|
377 |
bcopy(&(__FloatArrayInstPtr(aCollection)->f_element[__replStart]),
|
|
378 |
&(__FloatArrayInstPtr(self)->f_element[__start]),
|
|
379 |
sizeof(float) * __n);
|
|
380 |
RETURN(self);
|
|
381 |
}
|
5737
|
382 |
}
|
|
383 |
}
|
|
384 |
}
|
|
385 |
}
|
|
386 |
%}.
|
|
387 |
^ super replaceFrom:start to:stop with:aCollection startingAt:replStart
|
|
388 |
|
|
389 |
"
|
|
390 |
|f1 f2|
|
|
391 |
|
|
392 |
f1 := (1 to:5) asFloatArray.
|
|
393 |
f2 := #(10 9 8 7 6) asFloatArray.
|
|
394 |
f1 replaceFrom:1 to:3 with:f2 startingAt:3
|
|
395 |
"
|
|
396 |
! !
|
|
397 |
|
|
398 |
!FloatArray methodsFor:'queries'!
|
|
399 |
|
5768
|
400 |
absMax
|
|
401 |
"return the largest absolute value"
|
|
402 |
|
5816
|
403 |
|mm|
|
5768
|
404 |
|
|
405 |
mm := self minMax.
|
|
406 |
^ (mm at:1) abs max:(mm at:2) abs
|
|
407 |
|
|
408 |
"
|
|
409 |
|f1|
|
|
410 |
|
|
411 |
f1 := (1 to:1000) asFloatArray.
|
|
412 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 absMax ] ]
|
|
413 |
"
|
|
414 |
"
|
|
415 |
|f1|
|
|
416 |
|
|
417 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
418 |
f1 absMax
|
|
419 |
"
|
|
420 |
"
|
|
421 |
|f1|
|
|
422 |
|
|
423 |
f1 := FloatArray withAll:#(5 4 3 2 1).
|
|
424 |
f1 absMax
|
|
425 |
"
|
|
426 |
"
|
|
427 |
|f1|
|
|
428 |
|
|
429 |
f1 := FloatArray withAll:#(5 -4 3 2 1).
|
|
430 |
f1 absMax
|
|
431 |
"
|
|
432 |
"
|
|
433 |
|f1|
|
|
434 |
|
|
435 |
f1 := FloatArray withAll:#(5 -5 3 2 1).
|
|
436 |
f1 absMax
|
|
437 |
"
|
|
438 |
"
|
|
439 |
|f1|
|
|
440 |
|
|
441 |
f1 := FloatArray withAll:#(5 -6 3 2 1).
|
|
442 |
f1 absMax
|
|
443 |
"
|
|
444 |
!
|
|
445 |
|
7220
|
446 |
defaultElement
|
|
447 |
^ ShortFloat zero
|
|
448 |
!
|
|
449 |
|
5737
|
450 |
max
|
|
451 |
"return the largest element;
|
|
452 |
redefined for speed"
|
|
453 |
%{
|
8913
|
454 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
7220
|
455 |
int _sz = __floatArraySize(self);
|
5737
|
456 |
|
7220
|
457 |
if (_sz > 0) {
|
|
458 |
float *_p = __FloatArrayInstPtr(self)->f_element;
|
|
459 |
float _max;
|
5737
|
460 |
|
7220
|
461 |
_max = _p[0];
|
|
462 |
if (_sz > 1) {
|
|
463 |
int _i;
|
|
464 |
float _prev, _this;
|
5737
|
465 |
|
7220
|
466 |
/* how about inline-mmx-asm for this ... */
|
|
467 |
_this = _p[1];
|
|
468 |
for (_i=2; _i<_sz; _i++) {
|
|
469 |
_prev = _this;
|
|
470 |
_this = _p[_i];
|
|
471 |
if (_prev > _max) _max = _prev;
|
5737
|
472 |
}
|
7220
|
473 |
if (_this > _max) _max = _this;
|
5737
|
474 |
}
|
7220
|
475 |
RETURN (__MKFLOAT(_max));
|
5737
|
476 |
}
|
7220
|
477 |
}
|
5737
|
478 |
%}.
|
7220
|
479 |
^ super max
|
5737
|
480 |
|
7220
|
481 |
"
|
|
482 |
|f1|
|
5737
|
483 |
|
7220
|
484 |
f1 := (1 to:1000) asFloatArray.
|
|
485 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ]
|
|
486 |
"
|
|
487 |
"
|
|
488 |
|f1|
|
5737
|
489 |
|
7220
|
490 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
491 |
f1 max
|
|
492 |
"
|
|
493 |
"
|
|
494 |
|f1|
|
5737
|
495 |
|
7220
|
496 |
f1 := FloatArray withAll:#(5 4 3 2 1).
|
|
497 |
f1 max
|
|
498 |
"
|
5737
|
499 |
!
|
|
500 |
|
|
501 |
min
|
|
502 |
"return the largest element;
|
|
503 |
redefined for speed"
|
|
504 |
%{
|
8913
|
505 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
7220
|
506 |
int _sz = __floatArraySize(self);
|
5737
|
507 |
|
7220
|
508 |
if (_sz > 0) {
|
|
509 |
float *_p = __FloatArrayInstPtr(self)->f_element;
|
|
510 |
float _min;
|
5737
|
511 |
|
7220
|
512 |
_min = _p[0];
|
|
513 |
if (_sz > 1) {
|
|
514 |
int _i;
|
|
515 |
float _prev, _this;
|
5737
|
516 |
|
7220
|
517 |
/* how about inline-mmx-asm for this ... */
|
|
518 |
_this = _p[1];
|
|
519 |
for (_i=2; _i<_sz; _i++) {
|
|
520 |
_prev = _this;
|
|
521 |
_this = _p[_i];
|
|
522 |
if (_prev < _min) _min = _prev;
|
5737
|
523 |
}
|
7220
|
524 |
if (_this < _min) _min = _this;
|
5737
|
525 |
}
|
7220
|
526 |
RETURN (__MKFLOAT(_min));
|
5737
|
527 |
}
|
7220
|
528 |
}
|
5737
|
529 |
%}.
|
7220
|
530 |
^ super min
|
5737
|
531 |
|
7220
|
532 |
"
|
|
533 |
|f1|
|
5737
|
534 |
|
7220
|
535 |
f1 := (1 to:1000) asFloatArray.
|
|
536 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
|
|
537 |
"
|
|
538 |
"
|
|
539 |
|f1|
|
5737
|
540 |
|
7220
|
541 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
542 |
f1 min
|
|
543 |
"
|
|
544 |
"
|
|
545 |
|f1|
|
5737
|
546 |
|
7220
|
547 |
f1 := FloatArray withAll:#(5 4 3 2 1).
|
|
548 |
f1 min
|
|
549 |
"
|
5737
|
550 |
!
|
|
551 |
|
|
552 |
minMax
|
|
553 |
"return an array holding the smallest and largest element;
|
|
554 |
redefined for speed"
|
|
555 |
|
|
556 |
|min max|
|
|
557 |
|
|
558 |
%{
|
8913
|
559 |
if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
|
7220
|
560 |
int _sz = __floatArraySize(self);
|
|
561 |
if (_sz > 0) {
|
|
562 |
int _i;
|
|
563 |
float *_p = __FloatArrayInstPtr(self)->f_element;
|
|
564 |
float _min, _max;
|
5737
|
565 |
|
7220
|
566 |
_min = _max = _p[0];
|
5737
|
567 |
|
7220
|
568 |
if (_sz > 1) {
|
|
569 |
float _this = _p[1];
|
|
570 |
float _prev;
|
|
571 |
|
|
572 |
/* how about inline-mmx-asm for this ... */
|
|
573 |
for (_i=2; _i<_sz; _i++) {
|
|
574 |
_prev = _this;
|
|
575 |
_this = _p[_i];
|
|
576 |
if (_prev < _min) {
|
|
577 |
_min = _prev;
|
|
578 |
} else if (_prev > _max) {
|
|
579 |
_max = _prev;
|
5737
|
580 |
}
|
|
581 |
}
|
7220
|
582 |
if (_this < _min) {
|
|
583 |
_min = _this;
|
|
584 |
} else if (_this > _max) {
|
|
585 |
_max = _this;
|
|
586 |
}
|
5737
|
587 |
}
|
7220
|
588 |
min = __MKFLOAT(_min);
|
|
589 |
max = __MKFLOAT(_max);
|
|
590 |
RETURN (__ARRAY_WITH2(min, max));
|
5737
|
591 |
}
|
7220
|
592 |
}
|
5737
|
593 |
%}.
|
7220
|
594 |
^ Array with:(super min) with:(super max)
|
5737
|
595 |
|
7220
|
596 |
"
|
|
597 |
|f1|
|
|
598 |
|
|
599 |
f1 := (1 to:1000) asFloatArray.
|
|
600 |
Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ]
|
|
601 |
"
|
|
602 |
"
|
|
603 |
|f1|
|
5737
|
604 |
|
7220
|
605 |
f1 := FloatArray withAll:#(1 2 3 4 5).
|
|
606 |
f1 minMax
|
|
607 |
"
|
|
608 |
"
|
|
609 |
|f1|
|
5737
|
610 |
|
7220
|
611 |
f1 := FloatArray withAll:#(5 4 3 2 1).
|
|
612 |
f1 minMax
|
|
613 |
"
|
5737
|
614 |
! !
|
|
615 |
|
628
|
616 |
!FloatArray class methodsFor:'documentation'!
|
603
|
617 |
|
|
618 |
version
|
8913
|
619 |
^ '$Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.20 2005-07-08 17:15:01 cg Exp $'
|
88
|
620 |
! !
|