DoubleArray.st
author Stefan Vogel <sv@exept.de>
Thu, 16 Apr 2020 16:57:05 +0200
changeset 25362 f1606835f9fb
parent 24435 fb2ab71b12a4
permissions -rw-r--r--
#TUNING by stefan class: Win32OperatingSystem class changed: #getProcessId cache my own process id
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24435
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
     1
"{ Encoding: utf8 }"
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
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
24434
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
    90
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
    91
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    92
!DoubleArray class methodsFor:'queries'!
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    93
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    94
elementByteSize
16850
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    95
    "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
    96
     Here, 8 is returned"
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    97
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    98
    ^ 8
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
    "Created: / 15-09-2011 / 14:12:46 / cg"
24434
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   101
!
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   102
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   103
epsilon
24435
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   104
    "return the maximum relative spacing of my elements
24434
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   105
     (i.e. the value-delta of the least significant bit)"
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   106
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   107
    ^ Float epsilon
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   108
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   109
    "Created: / 19-07-2019 / 17:16:25 / Claus Gittinger"
24435
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   110
!
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   111
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   112
precision
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   113
    "answer the precision (the number of bits in the mantissa) of my elements (in bits)
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   114
     This is an IEEE halffloat, where only the fraction from the normalized mantissa is stored
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   115
     and so there is a hidden bit and the mantissa is actually represented by 53 binary digits
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   116
     (although only 52 are needed in the binary representation)"
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   117
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   118
    ^ Float precision
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   119
fb2ab71b12a4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24434
diff changeset
   120
    "Created: / 19-07-2019 / 17:23:12 / Claus Gittinger"
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   121
! !
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   122
24434
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   123
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   124
!DoubleArray methodsFor:'queries'!
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   125
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   126
defaultElement
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   127
    ^ Float zero
20301
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   128
!
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   129
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   130
isValidElement:anObject
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   131
    "return true, if I can hold this kind of object"
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   132
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   133
    ^ anObject isNumber
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   134
!
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
max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   137
    "return the largest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   138
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   139
%{  /* NOCONTEXT */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   140
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   141
        INT _sz = __doubleArraySize(self);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   142
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   143
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   144
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   145
            double _max;
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
            _max = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   148
            if (_sz > 1) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   149
                INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   150
                double _prev, _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   151
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   152
                /* how about inline-mmx-asm for this ... */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   153
                _this = _p[1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   154
                for (_i=2; _i<_sz; _i++) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   155
                    _prev = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   156
                    _this = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   157
                    if (_prev > _max) _max = _prev;
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
                if (_this > _max) _max = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   160
            }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   161
            RETURN (__MKFLOAT(_max));
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
    }
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
    ^ super max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   166
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
     |f1|
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
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   171
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   172
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   173
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   174
     |a1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   175
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   176
     a1 := (1 to:10000) asArray collect:#asFloat.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   177
     Time millisecondsToRun:[ 1000 timesRepeat:[ a1 max ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   178
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   179
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   180
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   181
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   182
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   183
     f1 max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   184
    "
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
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   187
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   188
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   189
     f1 max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   190
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   191
!
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
min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   194
    "return the smallest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   195
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   196
%{  /* NOCONTEXT */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   197
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   198
        INT _sz = __doubleArraySize(self);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   199
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   200
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   201
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   202
            double _min;
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
            _min = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   205
            if (_sz > 1) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   206
                INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   207
                double _prev, _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   208
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   209
                /* how about inline-mmx-asm for this ... */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   210
                _this = _p[1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   211
                for (_i=2; _i<_sz; _i++) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   212
                    _prev = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   213
                    _this = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   214
                    if (_prev < _min) _min = _prev;
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
                if (_this < _min) _min = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   217
            }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   218
            RETURN (__MKFLOAT(_min));
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
    }
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
    ^ super min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   223
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
     |f1|
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
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   228
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   229
    "
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
     |a1|
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
     a1 := (1 to:10000) asArray collect:#asFloat.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   234
     Time millisecondsToRun:[ 1000 timesRepeat:[ a1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   235
    "
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
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   238
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   239
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   240
     f1 min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   241
    "
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
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   244
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   245
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   246
     f1 min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   247
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   248
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   249
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   250
minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   251
    "return a Tuple holding the smallest and largest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   252
     redefined for speed"
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
    |min max empty|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   255
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   256
%{  
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   257
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
21080
ffebd509a3ae #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20314
diff changeset
   258
        INT _sz = __doubleArraySize(self);
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   259
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   260
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   261
            INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   262
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   263
            double _min, _max;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   264
            OBJ ret;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   265
            
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   266
            _min = _max = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   267
            for (_i=_sz-1; _i>0; _i-=2) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   268
                double _v1 = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   269
                double _v2 = _p[_i-1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   270
                if (_v1 < _v2) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   271
                    if (_v1 < _min) _min = _v1;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   272
                    if (_v2 > _max) _max = _v2;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   273
                } else {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   274
                    if (_v2 < _min) _min = _v2;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   275
                    if (_v1 > _max) _max = _v1;
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
            }
21080
ffebd509a3ae #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20314
diff changeset
   278
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   279
            min = __MKFLOAT(_min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   280
            __PROTECT__(min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   281
            max = __MKFLOAT(_max);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   282
            __UNPROTECT__(min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   283
            RETURN (__ARRAY_WITH2(min, max));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   284
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   285
        empty = true;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   286
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   287
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   288
    empty == true ifTrue:[
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   289
        ^ self emptyCollectionError.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   290
    ].
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   291
    "/ fallback if no primitive code
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   292
    ^ super minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   293
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   294
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   295
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   296
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   297
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   298
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   299
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   300
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   301
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   302
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   303
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   304
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   305
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   306
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   307
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   308
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   309
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   310
     f1 minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   311
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   312
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   313
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   315
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   316
     f1 minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   317
    "
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   318
! !
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   319
23797
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   320
!DoubleArray methodsFor:'testing'!
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   321
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   322
isFloatArray
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   323
    "return true if the receiver has float elements.
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   324
     These are Float, Double- and HalfFloat arrays"
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   325
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   326
    ^ true
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   327
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   328
    "Created: / 02-03-2019 / 23:13:34 / Claus Gittinger"
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   329
! !
119ce5d12f09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21080
diff changeset
   330
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   331
!DoubleArray methodsFor:'vector arithmetic'!
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   332
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   333
dot: aFloatVector
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   334
    "Return the dot product of the receiver and the argument.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   335
     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
   336
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   337
    | mySize result |
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   338
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   339
%{
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   340
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   341
     && (__ClassInstPtr(__qClass(aFloatVector))->c_ninstvars == __mkSmallInteger(0))) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   342
        INT __mySize = __doubleArraySize(self);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   343
        double __result = 0.0;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   344
        double *__p1 = __DoubleArrayInstPtr(self)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   345
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   346
        if (__mySize > 0) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   347
            if (__isFloats(aFloatVector)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   348
                INT __otherSize = __floatArraySize(aFloatVector);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   349
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   350
                if (__mySize == __otherSize) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   351
                    float *__p2 = __FloatArrayInstPtr(aFloatVector)->f_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   352
                    INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   353
                    /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   354
                    for (__i=0; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   355
                        __result += (__p1[__i] * __p2[__i]);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   356
                    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   357
                    RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   358
                }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   359
            } else if (__isDoubles(aFloatVector)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   360
                INT __otherSize = __doubleArraySize(aFloatVector);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   361
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   362
                if (__mySize == __otherSize) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   363
                    double *__p2 = __DoubleArrayInstPtr(aFloatVector)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   364
                    INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   365
                    /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   366
                    for (__i=0; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   367
                        __result += (__p1[__i] * __p2[__i]);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   368
                    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   369
                    RETURN (__MKFLOAT(__result));
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
        }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   373
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   374
%}.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   375
    ^ super dot:aFloatVector
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   376
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   377
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   378
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   379
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   380
     v := #(2.0 2.0 1.0) asFloatArray.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   381
     v dot:v.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   382
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   383
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   384
     |v1 v2|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   385
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   386
     v1 := FloatArray new:10000 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   387
     v2 := FloatArray new:10000 withAll:3.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   388
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   389
        10000 timesRepeat:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   390
          v1 dot:v2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   391
        ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   392
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   393
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   394
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   395
    "Created: / 29-05-2007 / 13:13:39 / cg"
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   396
!
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   397
24307
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   398
esum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   399
    "Return the sum of the elements.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   400
     Reduces accumulated rounding errors.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   401
     This is an experimental algorithm"
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   402
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   403
%{
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   404
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   405
        INT __mySize = __doubleArraySize(self);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   406
        double __sum = 0.0;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   407
        double *__pf = __DoubleArrayInstPtr(self)->d_element;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   408
        #define NBITS_EXP 11
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   409
        #define NIDX_EXP  ((1<<NBITS_EXP))
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   410
        #define MASK_EXP  (NIDX_EXP-1)
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   411
        double sumsPerE[ NIDX_EXP];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   412
        int __i, __minIdx = MASK_EXP, __maxIdx = 0;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   413
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   414
        memset(sumsPerE, 0, sizeof(double)*NIDX_EXP);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   415
        
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   416
        for (__i=0; __i<__mySize; __i++) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   417
            union {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   418
                double f;
24333
e6d6a165972d Replace uint32_t (not known in mingw)
Stefan Vogel <sv@exept.de>
parents: 24307
diff changeset
   419
                unsigned int32 ui32[2];
24307
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   420
            } u;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   421
            int exp;
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
            u.f = __pf[__i];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   424
#ifdef __LSBFIRST__
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   425
            exp = (u.ui32[1] >> (32-1-NBITS_EXP)) & MASK_EXP;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   426
#else
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   427
            exp = (u.ui32[0] >> ((32-1-NBITS_EXP)) & MASK_EXP;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   428
#endif
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   429
            // 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
   430
            // 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
   431
            sumsPerE[exp] += u.f;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   432
            __minIdx = exp < __minIdx ? exp : __minIdx;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   433
            __maxIdx = exp > __maxIdx ? exp : __maxIdx;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   434
        }
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
        // printf("low:%d high:%d\n", __minIdx, __maxIdx);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   437
        for (__i=__maxIdx; __i>=__minIdx; __i--) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   438
            __sum += sumsPerE[__i];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   439
        }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   440
        RETURN (__MKFLOAT(__sum));
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   441
    }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   442
%}.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   443
    ^ super sum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   444
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   445
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   446
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   447
     v := #(2.0 2.0 1.0 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   448
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   449
     v esum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   450
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   451
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   452
     v := #(1e100 1.0 -1e100 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   453
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   454
     v esum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   455
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   456
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   457
    "Created: / 09-06-2019 / 13:48:38 / Claus Gittinger"
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   458
!
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   459
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   460
hornerMultiplyAndAdd:x
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   461
    "primitive support for horner's-method computation of polynomials.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   462
     The vector is interpreted as providing the factors for a polynomial,
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   463
        an*x^n + (an-1)*x^(n-1) + ... + a2(x) + a1
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   464
     where the ai are the elements of the Array.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   465
     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
   466
     This is inlined c-code, which may get compiled to fast machine code,
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   467
     using multiply-and-add or vector instructions, if the CPU/Compiler support them."
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   468
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   469
    | mySize result |
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   470
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   471
%{
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   472
    double __x;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   473
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   474
    if (__isFloat(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   475
        __x = __floatVal(x);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   476
    } else if (__isShortFloat(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   477
        __x = (double)__shortFloatVal(x);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   478
    } else if (__isSmallInteger(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   479
        __x = (double)(__intVal(x));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   480
    } else {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   481
        goto getOutOfHere;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   482
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   483
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   484
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   485
        INT __mySize = __doubleArraySize(self);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   486
        double *__elements = __DoubleArrayInstPtr(self)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   487
        double __result = __elements[0];
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   488
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   489
        if (__mySize > 1) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   490
            INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   491
            /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   492
            for (__i=1; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   493
                __result = (__result * __x) + __elements[__i];
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   494
            }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   495
        }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   496
        RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   497
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   498
getOutOfHere: ;    
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   499
%}.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   500
    ^ super hornerMultiplyAndAdd:x
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   501
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   502
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   503
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   504
     v := #(2.0 3.0 4.0) asDoubleArray.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   505
     v  hornerMultiplyAndAdd:10.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   506
    
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   507
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   508
     v := Array new:100 withAll:2.0.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   509
     v hornerMultiplyAndAdd:10
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   510
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   511
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   512
     v := Array new:100 withAll:2.0.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   513
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   514
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   515
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   516
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   517
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   518
     v := FloatArray new:100 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   519
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   520
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   521
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   522
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   523
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   524
     v := DoubleArray new:100 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   525
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   526
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   527
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   528
    "
24307
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   529
!
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   530
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   531
sum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   532
    "Return the sum of the elements.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   533
     May suffer from accumulated rounding error"
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   534
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   535
%{
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   536
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   537
        INT __mySize = __doubleArraySize(self);
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   538
        double __sum = 0.0;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   539
        double *__pf = __DoubleArrayInstPtr(self)->d_element;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   540
        int __i;
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   541
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   542
        /* how about inline-mmx-asm for this ... */
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   543
        for (__i=0; __i<__mySize; __i++) {
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   544
            __sum += __pf[__i];
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   545
        }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   546
        RETURN (__MKFLOAT(__sum));
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   547
    }
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   548
%}.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   549
    ^ super sum
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   550
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   551
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   552
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   553
     v := #(2.0 2.0 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   554
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   555
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   556
     |v|
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   557
     v := #(1e100 1.0 -1e100 1.0) asDoubleArray.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   558
     v sum.
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   559
    "
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   560
68d920e450f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23805
diff changeset
   561
    "Created: / 09-06-2019 / 10:43:10 / Claus Gittinger"
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   562
! !
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   563
24434
a99ad18a4ace #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 24333
diff changeset
   564
627
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
   565
!DoubleArray class methodsFor:'documentation'!
565
4f64b1faa6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   566
4f64b1faa6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   567
version
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   568
    ^ '$Header$'
16853
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   569
!
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   570
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   571
version_CVS
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   572
    ^ '$Header$'
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
   573
! !
16639
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
   574