FloatArray.st
changeset 22257 9ce7e373cf91
parent 21081 7c7d1c059ce9
child 22263 13169b366d63
equal deleted inserted replaced
22256:8ceb4fec6903 22257:9ce7e373cf91
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1993 by Claus Gittinger
     4  COPYRIGHT (c) 1993 by Claus Gittinger
     3               All Rights Reserved
     5               All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
    52     [author:]
    54     [author:]
    53         Claus Gittinger
    55         Claus Gittinger
    54 "
    56 "
    55 ! !
    57 ! !
    56 
    58 
    57 
       
    58 
       
    59 !FloatArray class methodsFor:'queries'!
    59 !FloatArray class methodsFor:'queries'!
    60 
    60 
    61 elementByteSize
    61 elementByteSize
    62     "for bit-like containers, return the number of bytes stored per element.
    62     "for bit-like containers, return the number of bytes stored per element.
    63      Here, 4 is returned"
    63      Here, 4 is returned"
    64 
    64 
    65     ^ 4
    65     ^ 4
    66 
    66 
    67     "Created: / 15-09-2011 / 14:12:39 / cg"
    67     "Created: / 15-09-2011 / 14:12:39 / cg"
    68 ! !
    68 ! !
    69 
       
    70 
    69 
    71 !FloatArray methodsFor:'copying'!
    70 !FloatArray methodsFor:'copying'!
    72 
    71 
    73 clone
    72 clone
    74     "return a copy of the receiver"
    73     "return a copy of the receiver"
   117                     OBJ __nObj;
   116                     OBJ __nObj;
   118                     int nBytes;
   117                     int nBytes;
   119 
   118 
   120                     // don't do this; sizeof returns the padded size!
   119                     // don't do this; sizeof returns the padded size!
   121                     // nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float);
   120                     // nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float);
   122                     nBytes = OHDR_SIZE + (__n * sizeof(float));
   121                     /* and what is the disadvantage of having the padded size?
   123 
   122                        in an 32 bit enviroments, we do need the padded size,
       
   123                        otherwise there are to less bytes allocated */
       
   124                     // nBytes = OHDR_SIZE + (__n * sizeof(float));
       
   125 
       
   126                     nBytes = sizeof(struct __FloatArray) + (__n - 1) * sizeof(float);
   124                     // printf("__n=%d nBytes=%d\n", __n, nBytes);
   127                     // printf("__n=%d nBytes=%d\n", __n, nBytes);
   125                     __nObj = __STX___new(nBytes);
   128                     __nObj = __STX___new(nBytes);
       
   129 
   126                     if (__nObj != nil) {
   130                     if (__nObj != nil) {
   127                         __objPtr(__nObj)->o_class = __qClass(self);
   131                         __objPtr(__nObj)->o_class = __qClass(self);
   128                         __STORE(__nObj, __qClass(self));
   132                         __STORE(__nObj, __qClass(self));
   129                         bcopy(__FloatArrayInstPtr(self)->f_element + __start,
   133                         // bcopy is marked as deprecated
   130                               __FloatArrayInstPtr(__nObj)->f_element,
   134                         // bcopy(
   131                               sizeof(float) * __n);
   135                         //     __FloatArrayInstPtr(self)->f_element,   
       
   136                         //     __FloatArrayInstPtr(__nObj)->f_element + __start,  
       
   137                         //     __n * sizeof(float));
       
   138 
       
   139                         memcpy(
       
   140                             __FloatArrayInstPtr(__nObj)->f_element + __start,
       
   141                             __FloatArrayInstPtr(self)->f_element,
       
   142                             __n * sizeof(float));
       
   143 
   132                         RETURN(__nObj);
   144                         RETURN(__nObj);
   133                     }
   145                     }
   134                 }
   146                 }
   135             }
   147             }
   136         }
   148         }
   140 
   152 
   141     "
   153     "
   142      |f1 f2|
   154      |f1 f2|
   143 
   155 
   144      f1 := FloatArray withAll:#(1 2 3 4 5 6).
   156      f1 := FloatArray withAll:#(1 2 3 4 5 6).
   145      f2 := f1 copyFrom:2 to:4.
   157      f2 := f1 copyFrom:1 to:3.
   146      f2
   158      f2                      
   147     "
   159     "
   148 !
   160 !
   149 
   161 
   150 replaceFrom:start to:stop with:aCollection startingAt:replStart
   162 replaceFrom:start to:stop with:aCollection startingAt:replStart
   151 %{
   163 %{
   942         10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
   954         10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
   943      ]
   955      ]
   944     "
   956     "
   945 ! !
   957 ! !
   946 
   958 
   947 
       
   948 !FloatArray class methodsFor:'documentation'!
   959 !FloatArray class methodsFor:'documentation'!
   949 
   960 
   950 version
   961 version
   951     ^ '$Header$'
   962     ^ '$Header$'
   952 !
   963 !