FloatArray.st
author Stefan Vogel <sv@exept.de>
Fri, 27 Oct 2017 16:14:37 +0200
branchexpecco_2_11_1_branch
changeset 22329 20662662693b
parent 21081 7c7d1c059ce9
child 21089 d50f93ca9622
child 22257 9ce7e373cf91
permissions -rw-r--r--
Add 2.11.0 Patch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
     3
              All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    12
"{ Package: 'stx:libbasic' }"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    13
18577
72ff8078cb76 class: FloatArray
Stefan Vogel <sv@exept.de>
parents: 17198
diff changeset
    14
"{ NameSpace: Smalltalk }"
72ff8078cb76 class: FloatArray
Stefan Vogel <sv@exept.de>
parents: 17198
diff changeset
    15
13826
ec58f3b538e5 class definition
Claus Gittinger <cg@exept.de>
parents: 13775
diff changeset
    16
AbstractNumberVector variableFloatSubclass:#FloatArray
21081
7c7d1c059ce9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20313
diff changeset
    17
	instanceVariableNames:''
7c7d1c059ce9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20313
diff changeset
    18
	classVariableNames:''
7c7d1c059ce9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20313
diff changeset
    19
	poolDictionaries:''
7c7d1c059ce9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20313
diff changeset
    20
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    23
!FloatArray class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    24
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    27
 COPYRIGHT (c) 1993 by Claus Gittinger
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    28
              All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    37
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    39
documentation
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    40
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    41
    FloatArrays store floats (and nothing else).
16638
45cb03e85f6a class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 15935
diff changeset
    42
    They have been added to support heavy duty number crunching and
19003
6ac2cb393fd7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18577
diff changeset
    43
    data exchange with openGL frameworks and other mass data libraries.
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    44
    See documentation in DoubleArray for more information.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    45
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    46
    [memory requirements:]
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    47
        OBJ-HEADER + (size * float-size)
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    48
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    49
    [See also:]
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    50
        DoubleArray Array
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    51
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    52
    [author:]
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    53
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    54
"
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    55
! !
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    56
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    57
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    58
13707
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    59
!FloatArray class methodsFor:'queries'!
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    60
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    61
elementByteSize
16849
c20bd756c33b class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16638
diff changeset
    62
    "for bit-like containers, return the number of bytes stored per element.
c20bd756c33b class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16638
diff changeset
    63
     Here, 4 is returned"
c20bd756c33b class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16638
diff changeset
    64
13707
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    65
    ^ 4
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    66
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    67
    "Created: / 15-09-2011 / 14:12:39 / cg"
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    68
! !
a8f395adfac2 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 12577
diff changeset
    69
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    70
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    71
!FloatArray methodsFor:'copying'!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    72
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    73
clone
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    74
    "return a copy of the receiver"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    75
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    76
    |newArr|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    77
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    78
    newArr := self class new:(self size).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    79
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    80
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    81
        INT _sz = __floatArraySize(self);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    82
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    83
        bcopy(__FloatArrayInstPtr(self)->f_element,
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    84
              __FloatArrayInstPtr(newArr)->f_element,
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    85
              sizeof(float) * _sz);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    86
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
    87
        RETURN (newArr);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    88
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    89
%}.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    90
    newArr replaceFrom:1 to:self size with:self startingAt:1.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    91
    ^ newArr
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    92
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    93
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    94
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    95
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    96
     f1 := FloatArray withAll:#(1 2 3 4 5).
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
    97
     f1 clone
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    98
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    99
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   100
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   101
copyFrom:start to:stop
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   102
    "return a partial copy of the receiver"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   103
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   104
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   105
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   106
        if (__bothSmallInteger(start, stop)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   107
            INT __start = __intVal(start) - 1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   108
            INT __stop = __intVal(stop) - 1 ;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   109
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   110
            if (__stop >= __start) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   111
                INT __sz = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   112
                // printf("o_size=%d floatArraySize=%d\n", __qSize(self), __sz);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   113
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   114
                if (((unsigned INT)__start < __sz)
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   115
                 && ((unsigned INT)__stop < __sz)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   116
                    INT __n = __stop - __start + 1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   117
                    OBJ __nObj;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   118
                    int nBytes;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   119
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   120
                    // don't do this; sizeof returns the padded size!
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   121
                    // nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   122
                    nBytes = OHDR_SIZE + (__n * sizeof(float));
20303
060fea1cfebe fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents: 20300
diff changeset
   123
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   124
                    // printf("__n=%d nBytes=%d\n", __n, nBytes);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   125
                    __nObj = __STX___new(nBytes);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   126
                    if (__nObj != nil) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   127
                        __objPtr(__nObj)->o_class = __qClass(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   128
                        __STORE(__nObj, __qClass(self));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   129
                        bcopy(__FloatArrayInstPtr(self)->f_element + __start,
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   130
                              __FloatArrayInstPtr(__nObj)->f_element,
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   131
                              sizeof(float) * __n);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   132
                        RETURN(__nObj);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   133
                    }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   134
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   135
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   136
        }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   137
    }
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   138
%}.
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   139
    ^ super copyFrom:start to:stop
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   140
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   141
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   142
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   143
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   144
     f1 := FloatArray withAll:#(1 2 3 4 5 6).
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   145
     f2 := f1 copyFrom:2 to:4.
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   146
     f2
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   147
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   148
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   149
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   150
replaceFrom:start to:stop with:aCollection startingAt:replStart
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   151
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   152
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   153
         && __isFloats(aCollection)
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   154
         && (__ClassInstPtr(__qClass(aCollection))->c_ninstvars == __mkSmallInteger(0))
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   155
         && __bothSmallInteger(start, stop)
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   156
         && __isSmallInteger(replStart)
18577
72ff8078cb76 class: FloatArray
Stefan Vogel <sv@exept.de>
parents: 17198
diff changeset
   157
    ) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   158
        INT __start = __intVal(start) - 1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   159
        INT __stop = __intVal(stop) - 1 ;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   160
        INT __replStart = __intVal(replStart) - 1 ;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   161
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   162
        if (__stop >= __start) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   163
            INT __sz = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   164
            INT __otherSz = __floatArraySize(aCollection);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   165
            INT __replStop = __replStart + (__stop-__start);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   166
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   167
            if (((unsigned INT)__start < __sz)
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   168
             && ((unsigned INT)__stop < __sz)
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   169
             && ((unsigned INT)__replStart < __otherSz)
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   170
             && ((unsigned INT)__replStop < __otherSz)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   171
                INT __n = __stop - __start + 1;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   172
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   173
                if (aCollection == self) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   174
                    memmove(&(__FloatArrayInstPtr(self)->f_element[__start]),
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   175
                            &(__FloatArrayInstPtr(aCollection)->f_element[__replStart]),
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   176
                            sizeof(float) * __n);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   177
                } else {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   178
                    memcpy(&(__FloatArrayInstPtr(self)->f_element[__start]),
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   179
                           &(__FloatArrayInstPtr(aCollection)->f_element[__replStart]),
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   180
                           sizeof(float) * __n);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   181
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   182
                RETURN(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   183
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   184
        }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   185
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   186
%}.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   187
    ^ super replaceFrom:start to:stop with:aCollection startingAt:replStart
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   188
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   189
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   190
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   191
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   192
     f1 := (1 to:5) asFloatArray.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   193
     f2 := #(10 9 8 7 6) asFloatArray.
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   194
     f1 replaceFrom:1 to:3 with:f2 startingAt:3
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   195
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   196
! !
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   197
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   198
!FloatArray methodsFor:'destructive arithmetic support'!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   199
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   200
primAbs
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   201
    "destructive absolute value of each element"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   202
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   203
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   204
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   205
        INT _sz = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   206
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   207
        float *_p = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   208
        float prev_p;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   209
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   210
        if (_sz > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   211
            /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   212
            prev_p = _p[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   213
            for (i=1; i<_sz; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   214
                float next_p = _p[i];
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   215
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   216
                if (prev_p < 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   217
                    _p[i-1] = -prev_p;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   218
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   219
                prev_p = next_p;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   220
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   221
            if (prev_p < 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   222
                _p[i-1] = -prev_p;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   223
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   224
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   225
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   226
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   227
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   228
    super primAbs
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   229
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   230
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   231
     |f|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   232
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   233
     f := FloatArray withAll:#(-1 2 -3 4 -5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   234
     f abs.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   235
     f
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   236
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   237
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   238
    "Created: / 30-05-2007 / 17:50:17 / cg"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   239
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   240
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   241
primAddArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   242
    "add the vector argument into the receiver (destructive).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   243
     The argument must be another vector"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   244
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   245
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   246
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   247
     && __isFloats(floatArray)
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   248
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   249
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   250
        INT _sz2 = __floatArraySize(floatArray);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   251
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   252
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   253
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   254
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   255
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   256
            if (_sz2 >= _sz1) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   257
                /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   258
                float prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   259
                float prev_p2 = _p2[0];
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   260
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   261
                for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   262
                    float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   263
                    float next_p2 = _p2[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   264
                    _p1[i-1] = prev_p1 + prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   265
                    prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   266
                    prev_p2 = next_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   267
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   268
                _p1[i-1] = prev_p1 + prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   269
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   270
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   271
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   272
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   273
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   274
    super primAddArray:floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   275
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   276
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   277
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   278
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   279
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   280
     f2 := FloatArray withAll:#(2 2 2 3 3).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   281
     f1 += f2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   282
     f1
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   283
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   284
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   285
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   286
primAddScalar: aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   287
    "add the scalar argument into the receiver (destructive)."
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   288
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   289
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   290
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   291
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   292
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   293
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   294
        float v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   295
        float prev_p1;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   296
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   297
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   298
            if (__isFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   299
                v = (float)(__floatVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   300
            } else  if (__isShortFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   301
                v = __shortFloatVal(aScalar);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   302
            } else if (__isSmallInteger(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   303
                v = (float)(__intVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   304
            } else
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   305
                goto badArg;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   306
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   307
            /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   308
            prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   309
            for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   310
                float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   311
                _p1[i-1] = prev_p1 + v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   312
                prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   313
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   314
            _p1[i-1] = prev_p1 + v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   315
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   316
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   317
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   318
    badArg: ;
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   319
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   320
    super primAddScalar:aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   321
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   322
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   323
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   324
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   325
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   326
     f1 += 2.0.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   327
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   328
     f1 += 2.0 asShortFloat.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   329
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   330
     f1 += 2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   331
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   332
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   333
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   334
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   335
primDivArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   336
    "divide the vector argument into the receiver (destructive).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   337
     The argument must be another vector"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   338
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   339
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   340
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   341
     && __isFloats(floatArray)
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   342
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   343
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   344
        INT _sz2 = __floatArraySize(floatArray);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   345
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   346
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   347
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   348
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   349
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   350
            if (_sz2 >= _sz1) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   351
                /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   352
                float prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   353
                float prev_p2 = _p2[0];
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   354
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   355
                for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   356
                    float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   357
                    float next_p2 = _p2[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   358
                    _p1[i-1] = prev_p1 / prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   359
                    prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   360
                    prev_p2 = next_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   361
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   362
                _p1[i-1] = prev_p1 / prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   363
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   364
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   365
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   366
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   367
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   368
    super primDivArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   369
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   370
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   371
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   372
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   373
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   374
     f2 := FloatArray withAll:#(2 2 2 3 3).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   375
     f1 /= f2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   376
     f1
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   377
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   378
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   379
    "Modified: / 29-05-2007 / 16:01:34 / cg"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   380
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   381
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   382
primDivScalar: aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   383
    "divide the scalar argument into the receiver (destructive)."
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   384
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   385
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   386
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   387
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   388
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   389
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   390
        float v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   391
        float prev_p1;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   392
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   393
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   394
            if (__isFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   395
                v = (float)(__floatVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   396
            } else  if (__isShortFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   397
                v = __shortFloatVal(aScalar);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   398
            } else if (__isSmallInteger(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   399
                v = (float)(__intVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   400
            } else
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   401
                goto badArg;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   402
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   403
            /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   404
            prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   405
            for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   406
                float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   407
                _p1[i-1] = prev_p1 / v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   408
                prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   409
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   410
            _p1[i-1] = prev_p1 / v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   411
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   412
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   413
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   414
    badArg: ;
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   415
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   416
    super primDivScalar:aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   417
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   418
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   419
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   420
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   421
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   422
     f1 /= 2.0.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   423
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   424
     f1 /= 2.0 asShortFloat.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   425
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   426
     f1 /= 2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   427
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   428
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   429
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   430
    "Modified: / 29-05-2007 / 16:01:39 / cg"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   431
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   432
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   433
primMulArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   434
    "multiply the vector argument into the receiver (destructive).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   435
     The argument must be another vector"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   436
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   437
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   438
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   439
     && __isFloats(floatArray)
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   440
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   441
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   442
        INT _sz2 = __floatArraySize(floatArray);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   443
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   444
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   445
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   446
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   447
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   448
            if (_sz2 >= _sz1) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   449
                float prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   450
                float prev_p2 = _p2[0];
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   451
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   452
                for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   453
                    float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   454
                    float next_p2 = _p2[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   455
                    _p1[i-1] = prev_p1 * prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   456
                    prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   457
                    prev_p2 = next_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   458
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   459
                _p1[i-1] = prev_p1 * prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   460
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   461
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   462
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   463
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   464
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   465
    super primMulArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   466
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   467
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   468
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   469
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   470
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   471
     f2 := FloatArray withAll:#(2 2 2 3 3).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   472
     f1 *= f2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   473
     f1
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   474
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   475
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   476
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   477
primMulScalar: aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   478
    "multiply the scalar argument into the receiver (destructive)."
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   479
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   480
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   481
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   482
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   483
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   484
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   485
        float v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   486
        float prev_p1;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   487
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   488
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   489
            if (__isFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   490
                v = (float)(__floatVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   491
            } else  if (__isShortFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   492
                v = __shortFloatVal(aScalar);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   493
            } else if (__isSmallInteger(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   494
                v = (float)(__intVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   495
            } else
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   496
                goto badArg;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   497
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   498
            /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   499
            prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   500
            for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   501
                float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   502
                _p1[i-1] = prev_p1 * v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   503
                prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   504
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   505
            _p1[i-1] = prev_p1 * v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   506
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   507
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   508
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   509
    badArg: ;
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   510
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   511
    super primMulScalar:aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   512
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   513
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   514
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   515
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   516
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   517
     f1 *= 2.0.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   518
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   519
     f1 *= 2.0 asShortFloat.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   520
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   521
     f1 *= 2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   522
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   523
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   524
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   525
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   526
primNegated
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   527
    "destructive negative value of each element"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   528
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   529
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   530
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   531
        INT _sz = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   532
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   533
        float *_p = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   534
        float prev_p;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   535
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   536
        if (_sz > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   537
            /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   538
            prev_p = _p[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   539
            for (i=1; i<_sz; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   540
                float next_p = _p[i];
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   541
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   542
                _p[i-1] = -prev_p;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   543
                prev_p = next_p;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   544
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   545
            _p[i-1] = -prev_p;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   546
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   547
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   548
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   549
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   550
    super primNegated
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   551
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   552
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   553
     |f|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   554
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   555
     f := FloatArray withAll:#(-1 2 -3 4 -5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   556
     f negated.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   557
     f
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   558
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   559
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   560
    "Created: / 30-05-2007 / 17:51:29 / cg"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   561
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   562
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   563
primSubtractArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   564
    "subtract the vector argument from the receiver (destructive).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   565
     The argument must be another vector"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   566
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   567
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   568
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   569
     && __isFloats(floatArray)
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   570
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   571
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   572
        INT _sz2 = __floatArraySize(floatArray);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   573
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   574
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   575
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   576
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   577
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   578
            if (_sz2 >= _sz1) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   579
                float prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   580
                float prev_p2 = _p2[0];
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   581
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   582
                for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   583
                    float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   584
                    float next_p2 = _p2[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   585
                    _p1[i-1] = prev_p1 - prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   586
                    prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   587
                    prev_p2 = next_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   588
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   589
                _p1[i-1] = prev_p1 - prev_p2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   590
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   591
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   592
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   593
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   594
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   595
    super primSubtractArray: floatArray
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   596
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   597
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   598
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   599
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   600
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   601
     f2 := FloatArray withAll:#(2 2 2 3 3).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   602
     f1 -= f2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   603
     f1
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   604
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   605
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   606
    "Created: / 30-05-2007 / 17:42:41 / cg"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   607
!
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   608
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   609
primSubtractScalar: aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   610
    "subtract the scalar argument from the receiver (destructive)."
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   611
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   612
%{
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   613
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   614
        INT _sz1 = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   615
        INT i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   616
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   617
        float v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   618
        float prev_p1;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   619
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   620
        if (_sz1 > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   621
            if (__isFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   622
                v = (float)(__floatVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   623
            } else  if (__isShortFloat(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   624
                v = __shortFloatVal(aScalar);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   625
            } else if (__isSmallInteger(aScalar)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   626
                v = (float)(__intVal(aScalar));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   627
            } else
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   628
                goto badArg;
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   629
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   630
            /* how about inline-mmx-asm for this... ? */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   631
            prev_p1 = _p1[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   632
            for (i=1; i<_sz1; i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   633
                float next_p1 = _p1[i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   634
                _p1[i-1] = prev_p1 - v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   635
                prev_p1 = next_p1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   636
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   637
            _p1[i-1] = prev_p1 - v;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   638
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   639
        RETURN (self);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   640
    }
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   641
    badArg: ;
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   642
%}.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   643
    super primSubtractScalar:aScalar
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   644
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   645
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   646
     |f1 f2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   647
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   648
     f1 := FloatArray withAll:#(1 2 3 4 5).
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   649
     f1 -= 2.0.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   650
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   651
     f1 -= 2.0 asShortFloat.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   652
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   653
     f1 -= 2.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   654
     Transcript showCR:f1.
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   655
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   656
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   657
    "Created: / 30-05-2007 / 17:43:06 / cg"
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   658
! !
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   659
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   660
!FloatArray methodsFor:'queries'!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   661
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   662
defaultElement
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   663
    ^ ShortFloat zero
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   664
!
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   665
20300
b67a6d272129 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19032
diff changeset
   666
isValidElement:anObject
b67a6d272129 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19032
diff changeset
   667
    "return true, if I can hold this kind of object"
b67a6d272129 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19032
diff changeset
   668
b67a6d272129 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19032
diff changeset
   669
    ^ anObject isNumber
b67a6d272129 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19032
diff changeset
   670
!
b67a6d272129 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19032
diff changeset
   671
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   672
minMax
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   673
    "return a Tuple holding the smallest and largest element;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   674
     redefined for speed"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   675
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   676
    |min max empty|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   677
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   678
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   679
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   680
        INT _sz = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   681
        
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   682
        if (_sz > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   683
            INT _i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   684
            float *_p = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   685
            float _min, _max;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   686
            OBJ retVal;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   687
            
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   688
            _min = _max = _p[0];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   689
            for (_i=_sz-1; _i>0; _i-=2) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   690
                float _v1 = _p[_i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   691
                float _v2 = _p[_i-1];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   692
                if (_v1 < _v2) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   693
                    if (_v1 < _min) _min = _v1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   694
                    if (_v2 > _max) _max = _v2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   695
                } else {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   696
                    if (_v2 < _min) _min = _v2;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   697
                    if (_v1 > _max) _max = _v1;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   698
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   699
            }
21081
7c7d1c059ce9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20313
diff changeset
   700
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   701
            min = __MKFLOAT(_min);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   702
            __PROTECT__(min);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   703
            max = __MKFLOAT(_max);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   704
            __UNPROTECT__(min);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   705
            RETURN (__ARRAY_WITH2(min, max));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   706
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   707
        empty = true;
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   708
    }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   709
%}.
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   710
    empty == true ifTrue:[
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   711
        ^ self emptyCollectionError.
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   712
    ].
21081
7c7d1c059ce9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20313
diff changeset
   713
    ^ Array with:(self min) with:(self max)
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   714
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   715
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   716
     |f1|
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   717
13774
f36d336cc5c0 changed: #minMax
Claus Gittinger <cg@exept.de>
parents: 13707
diff changeset
   718
     f1 := (1 to:10000) asFloatArray.
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   719
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ]
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   720
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   721
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   722
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   723
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   724
     f1 := FloatArray withAll:#(1 2 3 4 5).
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   725
     f1 minMax
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   726
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   727
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   728
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   729
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   730
     f1 := FloatArray withAll:#(1 2 3 4).
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   731
     f1 minMax
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   732
    "
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   733
    "
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   734
     |f1|
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   735
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   736
     f1 := FloatArray withAll:#(5 4 3 2 1).
14692
98e7a51e5d17 64bit fixes
Claus Gittinger <cg@exept.de>
parents: 13826
diff changeset
   737
     f1 minMax
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   738
    "
13774
f36d336cc5c0 changed: #minMax
Claus Gittinger <cg@exept.de>
parents: 13707
diff changeset
   739
f36d336cc5c0 changed: #minMax
Claus Gittinger <cg@exept.de>
parents: 13707
diff changeset
   740
    "Modified (comment): / 07-10-2011 / 13:03:30 / cg"
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   741
!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   742
12577
a3224998ea6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11212
diff changeset
   743
numFloats
a3224998ea6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11212
diff changeset
   744
    ^ self size
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   745
! !
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   746
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   747
!FloatArray methodsFor:'vector arithmetic'!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   748
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   749
dot: aFloatVector
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   750
    "Return the dot product of the receiver and the argument.
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   751
     Raises an error, if the argument is not of the same size as the receiver."
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   752
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   753
    | mySize result |
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   754
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   755
"/    <primitive:'primitiveDotProduct' module: 'FloatArrayPlugin'>
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   756
%{
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   757
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   758
     && (__ClassInstPtr(__qClass(aFloatVector))->c_ninstvars == __mkSmallInteger(0))) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   759
        INT __mySize = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   760
        double __result = 0.0;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   761
        float *__p1 = __FloatArrayInstPtr(self)->f_element;
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   762
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   763
        if (__mySize > 0) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   764
            if (__isFloats(aFloatVector)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   765
                INT __otherSize = __floatArraySize(aFloatVector);
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   766
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   767
                if (__mySize == __otherSize) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   768
                    float *__p2 = __FloatArrayInstPtr(aFloatVector)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   769
                    INT __i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   770
                    /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   771
                    for (__i=0; __i<__mySize; __i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   772
                        __result += (__p1[__i] * __p2[__i]);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   773
                    }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   774
                    RETURN (__MKFLOAT(__result));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   775
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   776
            } else if (__isDoubles(aFloatVector)) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   777
                INT __otherSize = __doubleArraySize(aFloatVector);
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   778
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   779
                if (__mySize == __otherSize) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   780
                    double *__p2 = __DoubleArrayInstPtr(aFloatVector)->d_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   781
                    INT __i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   782
                    /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   783
                    for (__i=0; __i<__mySize; __i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   784
                        __result += (__p1[__i] * __p2[__i]);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   785
                    }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   786
                    RETURN (__MKFLOAT(__result));
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   787
                }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   788
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   789
        }
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   790
    }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   791
%}.
15935
35582e2e065c class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 14692
diff changeset
   792
    ^ super dot:aFloatVector
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   793
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   794
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   795
     |v|
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   796
     v := #(2.0 2.0 1.0) asFloatArray.
19003
6ac2cb393fd7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18577
diff changeset
   797
     v dot:v.
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   798
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   799
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   800
     v := #(2.0 2.0 1.0) asDoubleArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   801
     v dot:v.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   802
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   803
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   804
     v := #(2.0 2.0 1.0).
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   805
     v dot:v.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   806
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   807
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   808
     v1 := #(2.0 2.0 1.0) asFloatArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   809
     v2 := #(2.0 2.0 1.0) asDoubleArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   810
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   811
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   812
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   813
     v1 := #(2.0 2.0 1.0) asDoubleArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   814
     v2 := #(2.0 2.0 1.0) asFloatArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   815
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   816
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   817
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   818
     v1 := #(2.0 2.0 1.0).
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   819
     v2 := #(2.0 2.0 1.0) asFloatArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   820
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   821
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   822
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   823
     v1 := #(2.0 2.0 1.0) asFloatArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   824
     v2 := #(2.0 2.0 1.0).
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   825
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   826
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   827
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   828
     v1 := #(2.0 2.0 1.0).
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   829
     v2 := #(2.0 2.0 1.0) asDoubleArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   830
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   831
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   832
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   833
     v1 := #(2.0 2.0 1.0) asDoubleArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   834
     v2 := #(2.0 2.0 1.0).
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   835
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   836
    "
20303
060fea1cfebe fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents: 20300
diff changeset
   837
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   838
    "
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   839
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   840
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   841
     v1 := Array new:10000 withAll:2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   842
     v2 := Array new:10000 withAll:3.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   843
     Time millisecondsToRun:[
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   844
        10000 timesRepeat:[
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   845
          v1 dot:v2.
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   846
        ]
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   847
     ]
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   848
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   849
    "
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   850
     |v1 v2|
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   851
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   852
     v1 := FloatArray new:10000 withAll:2.
19003
6ac2cb393fd7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18577
diff changeset
   853
     v2 := FloatArray new:10000 withAll:3.
17198
7518cd20d9d3 class: FloatArray
Claus Gittinger <cg@exept.de>
parents: 16849
diff changeset
   854
     Time millisecondsToRun:[
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   855
        10000 timesRepeat:[
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   856
          v1 dot:v2.
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   857
        ]
19003
6ac2cb393fd7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18577
diff changeset
   858
     ]
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   859
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   860
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   861
    "
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   862
     |v1 v2|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   863
     v1 := #(2.0 2.0 1.0) asFloatArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   864
     v2 := #(2.0 2.0 1.0 0.0) asDoubleArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   865
     v1 dot:v2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   866
    "
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   867
20303
060fea1cfebe fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents: 20300
diff changeset
   868
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   869
    "Created: / 29-05-2007 / 13:13:39 / cg"
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   870
!
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   871
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   872
hornerMultiplyAndAdd:x
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   873
    "primitive support for horner's-method computation of polynomials.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   874
     The vector is interpreted as providing the factors for a polynomial,
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   875
        an*x^n + (an-1)*x^(n-1) + ... + a2(x) + a1
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   876
     where the ai are the elements of the Array.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   877
     The highest rank factor is at the first position, the 0-rank constant at last.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   878
     This is inlined c-code, which may get compiled to fast machine code,
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   879
     using multiply-and-add or vector instructions, if the CPU/Compiler support them."
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   880
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   881
    | mySize result |
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   882
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   883
%{
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   884
    double __x;
20303
060fea1cfebe fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents: 20300
diff changeset
   885
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   886
    if (__isFloat(x)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   887
        __x = __floatVal(x);
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   888
    } else if (__isShortFloat(x)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   889
        __x = (double)__shortFloatVal(x);
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   890
    } else if (__isSmallInteger(x)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   891
        __x = (double)(__intVal(x));
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   892
    } else {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   893
        goto getOutOfHere;
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   894
    }
20303
060fea1cfebe fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents: 20300
diff changeset
   895
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   896
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   897
        INT __mySize = __floatArraySize(self);
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   898
        float *__elements = __FloatArrayInstPtr(self)->f_element;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   899
        double __result = __elements[0];
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   900
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   901
        if (__mySize > 1) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   902
            INT __i;
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   903
            /* how about inline-mmx-asm for this ... */
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   904
            for (__i=1; __i<__mySize; __i++) {
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   905
                __result = (__result * __x) + __elements[__i];
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   906
            }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   907
        }
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   908
        RETURN (__MKFLOAT(__result));
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   909
    }
20303
060fea1cfebe fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents: 20300
diff changeset
   910
getOutOfHere: ;
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   911
%}.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   912
    ^ super hornerMultiplyAndAdd:x
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   913
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   914
    "
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   915
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   916
     v := #(2.0 3.0 4.0) asFloatArray.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   917
     v  hornerMultiplyAndAdd:10.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   918
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   919
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   920
     v := Array new:100 withAll:2.0.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   921
     v hornerMultiplyAndAdd:10
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   922
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   923
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   924
     v := FloatArray new:100 withAll:2.0.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   925
     v hornerMultiplyAndAdd:10
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   926
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   927
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   928
     v := Array new:100 withAll:2.0.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   929
     Time millisecondsToRun:[
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   930
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   931
     ]
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   932
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   933
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   934
     v := FloatArray new:100 withAll:2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   935
     Time millisecondsToRun:[
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   936
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   937
     ]
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   938
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   939
     |v|
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   940
     v := DoubleArray new:100 withAll:2.
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   941
     Time millisecondsToRun:[
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   942
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   943
     ]
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   944
    "
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   945
! !
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   946
20313
1280e2eafb73 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20303
diff changeset
   947
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
   948
!FloatArray class methodsFor:'documentation'!
603
72bdeb24ccba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   949
72bdeb24ccba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   950
version
18577
72ff8078cb76 class: FloatArray
Stefan Vogel <sv@exept.de>
parents: 17198
diff changeset
   951
    ^ '$Header$'
12577
a3224998ea6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11212
diff changeset
   952
!
a3224998ea6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11212
diff changeset
   953
a3224998ea6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11212
diff changeset
   954
version_CVS
18577
72ff8078cb76 class: FloatArray
Stefan Vogel <sv@exept.de>
parents: 17198
diff changeset
   955
    ^ '$Header$'
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
   956
! !
19032
67c02dbf742d #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19003
diff changeset
   957