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