441 f1 := FloatArray withAll:#(5 -6 3 2 1). |
441 f1 := FloatArray withAll:#(5 -6 3 2 1). |
442 f1 absMax |
442 f1 absMax |
443 " |
443 " |
444 ! |
444 ! |
445 |
445 |
|
446 defaultElement |
|
447 ^ ShortFloat zero |
|
448 ! |
|
449 |
446 max |
450 max |
447 "return the largest element; |
451 "return the largest element; |
448 redefined for speed" |
452 redefined for speed" |
449 %{ |
453 %{ |
450 if (__ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) { |
454 if (__ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) { |
451 int _sz = __floatArraySize(self); |
455 int _sz = __floatArraySize(self); |
452 |
456 |
453 if (_sz > 0) { |
457 if (_sz > 0) { |
454 float *_p = __FloatArrayInstPtr(self)->f_element; |
458 float *_p = __FloatArrayInstPtr(self)->f_element; |
455 float _max; |
459 float _max; |
456 |
460 |
457 _max = _p[0]; |
461 _max = _p[0]; |
458 if (_sz > 1) { |
462 if (_sz > 1) { |
459 int _i; |
463 int _i; |
460 float _prev, _this; |
464 float _prev, _this; |
461 |
465 |
462 /* how about inline-mmx-asm for this ... */ |
466 /* how about inline-mmx-asm for this ... */ |
463 _this = _p[1]; |
467 _this = _p[1]; |
464 for (_i=2; _i<_sz; _i++) { |
468 for (_i=2; _i<_sz; _i++) { |
465 _prev = _this; |
469 _prev = _this; |
466 _this = _p[_i]; |
470 _this = _p[_i]; |
467 if (_prev > _max) _max = _prev; |
471 if (_prev > _max) _max = _prev; |
468 } |
|
469 if (_this > _max) _max = _this; |
|
470 } |
472 } |
471 RETURN (__MKFLOAT(_max)); |
473 if (_this > _max) _max = _this; |
472 } |
474 } |
473 } |
475 RETURN (__MKFLOAT(_max)); |
|
476 } |
|
477 } |
474 %}. |
478 %}. |
475 ^ super max |
479 ^ super max |
476 |
480 |
477 " |
481 " |
478 |f1| |
482 |f1| |
479 |
483 |
480 f1 := (1 to:1000) asFloatArray. |
484 f1 := (1 to:1000) asFloatArray. |
481 Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ] |
485 Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ] |
482 " |
486 " |
483 " |
487 " |
484 |f1| |
488 |f1| |
485 |
489 |
486 f1 := FloatArray withAll:#(1 2 3 4 5). |
490 f1 := FloatArray withAll:#(1 2 3 4 5). |
487 f1 max |
491 f1 max |
488 " |
492 " |
489 " |
493 " |
490 |f1| |
494 |f1| |
491 |
495 |
492 f1 := FloatArray withAll:#(5 4 3 2 1). |
496 f1 := FloatArray withAll:#(5 4 3 2 1). |
493 f1 max |
497 f1 max |
494 " |
498 " |
495 ! |
499 ! |
496 |
500 |
497 min |
501 min |
498 "return the largest element; |
502 "return the largest element; |
499 redefined for speed" |
503 redefined for speed" |
500 %{ |
504 %{ |
501 if (__ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) { |
505 if (__ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) { |
502 int _sz = __floatArraySize(self); |
506 int _sz = __floatArraySize(self); |
503 |
507 |
504 if (_sz > 0) { |
508 if (_sz > 0) { |
505 float *_p = __FloatArrayInstPtr(self)->f_element; |
509 float *_p = __FloatArrayInstPtr(self)->f_element; |
506 float _min; |
510 float _min; |
507 |
511 |
508 _min = _p[0]; |
512 _min = _p[0]; |
509 if (_sz > 1) { |
513 if (_sz > 1) { |
510 int _i; |
514 int _i; |
511 float _prev, _this; |
515 float _prev, _this; |
512 |
516 |
513 /* how about inline-mmx-asm for this ... */ |
517 /* how about inline-mmx-asm for this ... */ |
514 _this = _p[1]; |
518 _this = _p[1]; |
515 for (_i=2; _i<_sz; _i++) { |
519 for (_i=2; _i<_sz; _i++) { |
516 _prev = _this; |
520 _prev = _this; |
517 _this = _p[_i]; |
521 _this = _p[_i]; |
518 if (_prev < _min) _min = _prev; |
522 if (_prev < _min) _min = _prev; |
519 } |
|
520 if (_this < _min) _min = _this; |
|
521 } |
523 } |
522 RETURN (__MKFLOAT(_min)); |
524 if (_this < _min) _min = _this; |
523 } |
525 } |
524 } |
526 RETURN (__MKFLOAT(_min)); |
|
527 } |
|
528 } |
525 %}. |
529 %}. |
526 ^ super min |
530 ^ super min |
527 |
531 |
528 " |
532 " |
529 |f1| |
533 |f1| |
530 |
534 |
531 f1 := (1 to:1000) asFloatArray. |
535 f1 := (1 to:1000) asFloatArray. |
532 Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ] |
536 Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ] |
533 " |
537 " |
534 " |
538 " |
535 |f1| |
539 |f1| |
536 |
540 |
537 f1 := FloatArray withAll:#(1 2 3 4 5). |
541 f1 := FloatArray withAll:#(1 2 3 4 5). |
538 f1 min |
542 f1 min |
539 " |
543 " |
540 " |
544 " |
541 |f1| |
545 |f1| |
542 |
546 |
543 f1 := FloatArray withAll:#(5 4 3 2 1). |
547 f1 := FloatArray withAll:#(5 4 3 2 1). |
544 f1 min |
548 f1 min |
545 " |
549 " |
546 ! |
550 ! |
547 |
551 |
548 minMax |
552 minMax |
549 "return an array holding the smallest and largest element; |
553 "return an array holding the smallest and largest element; |
550 redefined for speed" |
554 redefined for speed" |
551 |
555 |
552 |min max| |
556 |min max| |
553 |
557 |
554 %{ |
558 %{ |
555 if (__ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) { |
559 if (__ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) { |
556 int _sz = __floatArraySize(self); |
560 int _sz = __floatArraySize(self); |
557 if (_sz > 0) { |
561 if (_sz > 0) { |
558 int _i; |
562 int _i; |
559 float *_p = __FloatArrayInstPtr(self)->f_element; |
563 float *_p = __FloatArrayInstPtr(self)->f_element; |
560 float _min, _max; |
564 float _min, _max; |
561 |
565 |
562 _min = _max = _p[0]; |
566 _min = _max = _p[0]; |
563 |
567 |
564 if (_sz > 1) { |
568 if (_sz > 1) { |
565 float _this = _p[1]; |
569 float _this = _p[1]; |
566 float _prev; |
570 float _prev; |
567 |
571 |
568 /* how about inline-mmx-asm for this ... */ |
572 /* how about inline-mmx-asm for this ... */ |
569 for (_i=2; _i<_sz; _i++) { |
573 for (_i=2; _i<_sz; _i++) { |
570 _prev = _this; |
574 _prev = _this; |
571 _this = _p[_i]; |
575 _this = _p[_i]; |
572 if (_prev < _min) { |
576 if (_prev < _min) { |
573 _min = _prev; |
577 _min = _prev; |
574 } else if (_prev > _max) { |
578 } else if (_prev > _max) { |
575 _max = _prev; |
579 _max = _prev; |
576 } |
|
577 } |
|
578 if (_this < _min) { |
|
579 _min = _this; |
|
580 } else if (_this > _max) { |
|
581 _max = _this; |
|
582 } |
580 } |
583 } |
581 } |
584 min = __MKFLOAT(_min); |
582 if (_this < _min) { |
585 max = __MKFLOAT(_max); |
583 _min = _this; |
586 RETURN (__ARRAY_WITH2(min, max)); |
584 } else if (_this > _max) { |
|
585 _max = _this; |
|
586 } |
587 } |
587 } |
588 } |
588 min = __MKFLOAT(_min); |
|
589 max = __MKFLOAT(_max); |
|
590 RETURN (__ARRAY_WITH2(min, max)); |
|
591 } |
|
592 } |
589 %}. |
593 %}. |
590 ^ Array with:super min with:super max |
594 ^ Array with:(super min) with:(super max) |
591 |
595 |
592 " |
596 " |
593 |f1| |
597 |f1| |
594 |
598 |
595 f1 := (1 to:1000) asFloatArray. |
599 f1 := (1 to:1000) asFloatArray. |
596 Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ] |
600 Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ] |
597 " |
601 " |
598 " |
602 " |
599 |f1| |
603 |f1| |
600 |
604 |
601 f1 := FloatArray withAll:#(1 2 3 4 5). |
605 f1 := FloatArray withAll:#(1 2 3 4 5). |
602 f1 minMax |
606 f1 minMax |
603 " |
607 " |
604 " |
608 " |
605 |f1| |
609 |f1| |
606 |
610 |
607 f1 := FloatArray withAll:#(5 4 3 2 1). |
611 f1 := FloatArray withAll:#(5 4 3 2 1). |
608 f1 minMax |
612 f1 minMax |
609 " |
613 " |
610 ! ! |
614 ! ! |
611 |
615 |
612 !FloatArray class methodsFor:'documentation'! |
616 !FloatArray class methodsFor:'documentation'! |
613 |
617 |
614 version |
618 version |
615 ^ '$Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.18 2001-02-28 13:14:13 stefan Exp $' |
619 ^ '$Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.19 2003-04-22 09:39:26 cg Exp $' |
616 ! ! |
620 ! ! |