DoubleArray.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24333 e6d6a165972d
child 24434 a99ad18a4ace
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23797
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
     1
"{ Encoding: utf8 }"
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
	      All Rights Reserved
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    14
"{ Package: 'stx:libbasic' }"
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    15
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
    16
"{ NameSpace: Smalltalk }"
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
    17
23805
c9a1881f8deb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23797
diff changeset
    18
UnboxedFloatArray variableDoubleSubclass:#DoubleArray
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    19
	instanceVariableNames:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    20
	classVariableNames:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    21
	poolDictionaries:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    22
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    25
!DoubleArray class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    29
 COPYRIGHT (c) 1993 by Claus Gittinger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
	      All Rights Reserved
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    39
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    40
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    41
documentation
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    42
"
13825
a80eb51765c0 class definition
Claus Gittinger <cg@exept.de>
parents: 13708
diff changeset
    43
    DoubleArrays store doubleFloat values (and nothing else).
16639
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
    44
    They have been added to support heavy duty number crunching and
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
    45
    data exchange with openGL frameworks and other mass data libraries
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
    46
    somewhat better than other smalltalks do. 
362
claus
parents: 155
diff changeset
    47
    Storing Floats & Doubles in these objects (instead of Arrays)
claus
parents: 155
diff changeset
    48
    has some benefits:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    49
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    50
    1) since the values are stored directly (instead of pointers to them)
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    51
       both access overhead and garbage collect overhead is minimized.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    52
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    53
    2) they can be much faster passed to c functions (such as graphics 
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    54
       libraries or heavy duty math packages), since the double values
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    55
       come packed and can be used in C by using a (double *) or double[].
362
claus
parents: 155
diff changeset
    56
       There is no need to loop over the array extracting doubles.      
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    57
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    58
    3) they could (in theory) be much more easily be processed by things like
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    59
       vector and array processors
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    60
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    61
    Be aware however, that Float- and DoubleArrays are not supported in other
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    62
    smalltalks - your program will thus become somewhat less portable.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    63
    (since their protocol is the same as normal arrays filled with floats,
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    64
     they can of course be easily simulated - a bit slower though)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
2820
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    66
    However, they could be simulated by a ByteArray, using doubleAt: and 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    67
    doubleAtPut: messages to access the elements, but that seems a bit
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    68
    clumsy and unelegant. Also, the stc-compiler may learn how to deal
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    69
    with Float- and DoubleArrays, making accesses very fast in the future.
2820
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    70
    Hint: if you use doubleArrays in your application and must port it
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    71
    to some other smalltalk, define a DoubleArray class there, which is derived
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    72
    from ByteArray, and add access methods.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
2145
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    74
    Of course, DoubleArray can be subclassed,
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    75
    and named instance variables can be added there.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
362
claus
parents: 155
diff changeset
    77
    See example uses in the GLX interface and GLDemos.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    78
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 2820
diff changeset
    79
    [memory requirements:]
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 2820
diff changeset
    80
        OBJ-HEADER + (size * double-size)
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 2820
diff changeset
    81
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    82
    [See also:]
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    83
        FloatArray Array
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    84
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    85
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    86
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    87
"
627
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    88
! !
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    89
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    90
!DoubleArray class methodsFor:'queries'!
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    91
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    92
elementByteSize
16850
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    93
    "for bit-like containers, return the number of bytes stored per element.
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    94
     Here, 8 is returned"
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    95
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    96
    ^ 8
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    97
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    98
    "Created: / 15-09-2011 / 14:12:46 / cg"
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    99
! !
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   100
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   101
!DoubleArray methodsFor:'queries'!
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   102
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   103
defaultElement
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   104
    ^ Float zero
20301
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   105
!
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   106
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   107
isValidElement:anObject
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   108
    "return true, if I can hold this kind of object"
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   109
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   110
    ^ anObject isNumber
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   111
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   112
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   113
max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   114
    "return the largest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   115
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   116
%{  /* NOCONTEXT */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   117
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   118
        INT _sz = __doubleArraySize(self);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   119
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   120
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   121
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   122
            double _max;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   123
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   124
            _max = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   125
            if (_sz > 1) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   126
                INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   127
                double _prev, _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   128
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   129
                /* how about inline-mmx-asm for this ... */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   130
                _this = _p[1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   131
                for (_i=2; _i<_sz; _i++) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   132
                    _prev = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   133
                    _this = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   134
                    if (_prev > _max) _max = _prev;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   135
                }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   136
                if (_this > _max) _max = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   137
            }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   138
            RETURN (__MKFLOAT(_max));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   139
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   140
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   141
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   142
    ^ super max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   143
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   144
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   145
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   146
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   147
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   148
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   149
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   150
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   151
     |a1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   152
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   153
     a1 := (1 to:10000) asArray collect:#asFloat.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   154
     Time millisecondsToRun:[ 1000 timesRepeat:[ a1 max ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   155
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   156
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   157
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   158
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   159
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   160
     f1 max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   161
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   162
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   163
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   164
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   165
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   166
     f1 max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   167
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   168
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   169
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   170
min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   171
    "return the smallest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   172
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   173
%{  /* NOCONTEXT */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   174
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   175
        INT _sz = __doubleArraySize(self);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   176
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   177
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   178
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   179
            double _min;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   180
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   181
            _min = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   182
            if (_sz > 1) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   183
                INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   184
                double _prev, _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   185
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   186
                /* how about inline-mmx-asm for this ... */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   187
                _this = _p[1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   188
                for (_i=2; _i<_sz; _i++) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   189
                    _prev = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   190
                    _this = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   191
                    if (_prev < _min) _min = _prev;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   192
                }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   193
                if (_this < _min) _min = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   194
            }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   195
            RETURN (__MKFLOAT(_min));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   196
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   197
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   198
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   199
    ^ super min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   200
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   201
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   202
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   203
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   204
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   205
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   206
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   207
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   208
     |a1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   209
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   210
     a1 := (1 to:10000) asArray collect:#asFloat.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   211
     Time millisecondsToRun:[ 1000 timesRepeat:[ a1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   212
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   213
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   214
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   215
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   216
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   217
     f1 min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   218
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   219
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   220
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   221
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   222
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   223
     f1 min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   224
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   225
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   226
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   227
minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   228
    "return a Tuple holding the smallest and largest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   229
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   230
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   231
    |min max empty|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   232
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   233
%{  
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   234
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
21080
ffebd509a3ae #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20314
diff changeset
   235
        INT _sz = __doubleArraySize(self);
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   236
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   237
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   238
            INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   239
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   240
            double _min, _max;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   241
            OBJ ret;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   242
            
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   243
            _min = _max = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   244
            for (_i=_sz-1; _i>0; _i-=2) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   245
                double _v1 = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   246
                double _v2 = _p[_i-1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   247
                if (_v1 < _v2) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   248
                    if (_v1 < _min) _min = _v1;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   249
                    if (_v2 > _max) _max = _v2;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   250
                } else {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   251
                    if (_v2 < _min) _min = _v2;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   252
                    if (_v1 > _max) _max = _v1;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   253
                }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   254
            }
21080
ffebd509a3ae #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20314
diff changeset
   255
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   256
            min = __MKFLOAT(_min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   257
            __PROTECT__(min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   258
            max = __MKFLOAT(_max);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   259
            __UNPROTECT__(min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   260
            RETURN (__ARRAY_WITH2(min, max));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   261
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   262
        empty = true;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   263
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   264
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   265
    empty == true ifTrue:[
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   266
        ^ self emptyCollectionError.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   267
    ].
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   268
    "/ fallback if no primitive code
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   269
    ^ super minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   270
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   271
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   272
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   273
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   274
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   275
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   276
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   277
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   278
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   279
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   280
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   281
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   282
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   283
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   284
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   285
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   286
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   287
     f1 minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   288
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   289
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   290
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   291
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   292
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   293
     f1 minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   294
    "
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   295
! !
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   296
23797
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   297
!DoubleArray methodsFor:'testing'!
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   298
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   299
isFloatArray
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   300
    "return true if the receiver has float elements.
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   301
     These are Float, Double- and HalfFloat arrays"
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   302
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   303
    ^ true
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   304
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   305
    "Created: / 02-03-2019 / 23:13:34 / Claus Gittinger"
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   306
! !
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   307
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   308
!DoubleArray methodsFor:'vector arithmetic'!
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   309
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   310
dot: aFloatVector
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   311
    "Return the dot product of the receiver and the argument.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   312
     Raises an error, if the argument is not of the same size as the receiver."
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   313
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   314
    | mySize result |
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   315
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   316
%{
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   317
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   318
     && (__ClassInstPtr(__qClass(aFloatVector))->c_ninstvars == __mkSmallInteger(0))) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   319
        INT __mySize = __doubleArraySize(self);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   320
        double __result = 0.0;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   321
        double *__p1 = __DoubleArrayInstPtr(self)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   322
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   323
        if (__mySize > 0) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   324
            if (__isFloats(aFloatVector)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   325
                INT __otherSize = __floatArraySize(aFloatVector);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   326
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   327
                if (__mySize == __otherSize) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   328
                    float *__p2 = __FloatArrayInstPtr(aFloatVector)->f_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   329
                    INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   330
                    /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   331
                    for (__i=0; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   332
                        __result += (__p1[__i] * __p2[__i]);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   333
                    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   334
                    RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   335
                }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   336
            } else if (__isDoubles(aFloatVector)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   337
                INT __otherSize = __doubleArraySize(aFloatVector);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   338
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   339
                if (__mySize == __otherSize) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   340
                    double *__p2 = __DoubleArrayInstPtr(aFloatVector)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   341
                    INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   342
                    /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   343
                    for (__i=0; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   344
                        __result += (__p1[__i] * __p2[__i]);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   345
                    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   346
                    RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   347
                }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   348
            }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   349
        }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   350
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   351
%}.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   352
    ^ super dot:aFloatVector
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   353
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   354
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   355
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   356
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   357
     v := #(2.0 2.0 1.0) asFloatArray.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   358
     v dot:v.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   359
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   360
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   361
     |v1 v2|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   362
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   363
     v1 := FloatArray new:10000 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   364
     v2 := FloatArray new:10000 withAll:3.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   365
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   366
        10000 timesRepeat:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   367
          v1 dot:v2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   368
        ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   369
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   370
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   371
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   372
    "Created: / 29-05-2007 / 13:13:39 / cg"
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   373
!
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   374
24307
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   375
esum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   376
    "Return the sum of the elements.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   377
     Reduces accumulated rounding errors.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   378
     This is an experimental algorithm"
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   379
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   380
%{
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   381
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   382
        INT __mySize = __doubleArraySize(self);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   383
        double __sum = 0.0;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   384
        double *__pf = __DoubleArrayInstPtr(self)->d_element;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   385
        #define NBITS_EXP 11
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   386
        #define NIDX_EXP  ((1<<NBITS_EXP))
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   387
        #define MASK_EXP  (NIDX_EXP-1)
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   388
        double sumsPerE[ NIDX_EXP];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   389
        int __i, __minIdx = MASK_EXP, __maxIdx = 0;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   390
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   391
        memset(sumsPerE, 0, sizeof(double)*NIDX_EXP);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   392
        
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   393
        for (__i=0; __i<__mySize; __i++) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   394
            union {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   395
                double f;
24333
e6d6a165972d Replace uint32_t (not known in mingw)
Stefan Vogel <sv@exept.de>
parents: 24307
diff changeset
   396
                unsigned int32 ui32[2];
24307
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   397
            } u;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   398
            int exp;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   399
            
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   400
            u.f = __pf[__i];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   401
#ifdef __LSBFIRST__
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   402
            exp = (u.ui32[1] >> (32-1-NBITS_EXP)) & MASK_EXP;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   403
#else
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   404
            exp = (u.ui32[0] >> ((32-1-NBITS_EXP)) & MASK_EXP;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   405
#endif
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   406
            // printf("f:%04x %04x %04x %04x\n", u.ui32[0], u.ui32[1], u.ui32[2], u.ui32[3]); 
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   407
            // printf("e:%d %lf + %lf -> %lf\n", exp, sumsPerE[exp], u.f, (sumsPerE[exp]+u.f)); 
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   408
            sumsPerE[exp] += u.f;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   409
            __minIdx = exp < __minIdx ? exp : __minIdx;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   410
            __maxIdx = exp > __maxIdx ? exp : __maxIdx;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   411
        }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   412
        
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   413
        // printf("low:%d high:%d\n", __minIdx, __maxIdx);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   414
        for (__i=__maxIdx; __i>=__minIdx; __i--) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   415
            __sum += sumsPerE[__i];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   416
        }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   417
        RETURN (__MKFLOAT(__sum));
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   418
    }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   419
%}.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   420
    ^ super sum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   421
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   422
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   423
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   424
     v := #(2.0 2.0 1.0 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   425
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   426
     v esum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   427
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   428
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   429
     v := #(1e100 1.0 -1e100 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   430
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   431
     v esum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   432
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   433
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   434
    "Created: / 09-06-2019 / 13:48:38 / Claus Gittinger"
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   435
!
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   436
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   437
hornerMultiplyAndAdd:x
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   438
    "primitive support for horner's-method computation of polynomials.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   439
     The vector is interpreted as providing the factors for a polynomial,
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   440
        an*x^n + (an-1)*x^(n-1) + ... + a2(x) + a1
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   441
     where the ai are the elements of the Array.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   442
     The highest rank factor is at the first position, the 0-rank constant at last.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   443
     This is inlined c-code, which may get compiled to fast machine code,
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   444
     using multiply-and-add or vector instructions, if the CPU/Compiler support them."
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   445
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   446
    | mySize result |
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   447
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   448
%{
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   449
    double __x;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   450
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   451
    if (__isFloat(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   452
        __x = __floatVal(x);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   453
    } else if (__isShortFloat(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   454
        __x = (double)__shortFloatVal(x);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   455
    } else if (__isSmallInteger(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   456
        __x = (double)(__intVal(x));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   457
    } else {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   458
        goto getOutOfHere;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   459
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   460
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   461
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   462
        INT __mySize = __doubleArraySize(self);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   463
        double *__elements = __DoubleArrayInstPtr(self)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   464
        double __result = __elements[0];
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   465
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   466
        if (__mySize > 1) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   467
            INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   468
            /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   469
            for (__i=1; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   470
                __result = (__result * __x) + __elements[__i];
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   471
            }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   472
        }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   473
        RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   474
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   475
getOutOfHere: ;    
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   476
%}.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   477
    ^ super hornerMultiplyAndAdd:x
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   478
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   479
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   480
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   481
     v := #(2.0 3.0 4.0) asDoubleArray.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   482
     v  hornerMultiplyAndAdd:10.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   483
    
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   484
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   485
     v := Array new:100 withAll:2.0.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   486
     v hornerMultiplyAndAdd:10
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   487
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   488
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   489
     v := Array new:100 withAll:2.0.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   490
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   491
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   492
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   493
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   494
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   495
     v := FloatArray new:100 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   496
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   497
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   498
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   499
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   500
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   501
     v := DoubleArray new:100 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   502
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   503
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   504
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   505
    "
24307
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   506
!
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   507
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   508
sum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   509
    "Return the sum of the elements.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   510
     May suffer from accumulated rounding error"
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   511
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   512
%{
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   513
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   514
        INT __mySize = __doubleArraySize(self);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   515
        double __sum = 0.0;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   516
        double *__pf = __DoubleArrayInstPtr(self)->d_element;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   517
        int __i;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   518
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   519
        /* how about inline-mmx-asm for this ... */
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   520
        for (__i=0; __i<__mySize; __i++) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   521
            __sum += __pf[__i];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   522
        }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   523
        RETURN (__MKFLOAT(__sum));
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   524
    }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   525
%}.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   526
    ^ super sum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   527
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   528
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   529
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   530
     v := #(2.0 2.0 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   531
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   532
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   533
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   534
     v := #(1e100 1.0 -1e100 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   535
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   536
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   537
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   538
    "Created: / 09-06-2019 / 10:43:10 / Claus Gittinger"
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   539
! !
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   540
627
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
   541
!DoubleArray class methodsFor:'documentation'!
565
4f64b1faa6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   542
4f64b1faa6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   543
version
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   544
    ^ '$Header$'
16853
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   545
!
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   546
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   547
version_CVS
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   548
    ^ '$Header$'
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
   549
! !
16639
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
   550