FloatArray.st
changeset 12577 a3224998ea6c
parent 11212 8a6590cc1f4a
child 13707 a8f395adfac2
equal deleted inserted replaced
12576:47985f127034 12577:a3224998ea6c
    62      #(1 2 3 4) asFloatArray * 3  
    62      #(1 2 3 4) asFloatArray * 3  
    63      #(1 2 3 4) asFloatArray * #(1 2 3 4) asFloatArray
    63      #(1 2 3 4) asFloatArray * #(1 2 3 4) asFloatArray
    64     "
    64     "
    65 !
    65 !
    66 
    66 
    67 *= anObject
       
    68     "multiply the argument into the receiver (destructive).
       
    69      The argument may either be a scalar or another vector"
       
    70 
       
    71     ^ anObject isNumber
       
    72                 ifTrue:[self primMulScalar: anObject asFloat]
       
    73                 ifFalse:[self primMulArray: anObject]
       
    74 
       
    75     "
       
    76      |f|
       
    77 
       
    78      f := #(1 2 3 4) asFloatArray.
       
    79      f *= 3.
       
    80      f         
       
    81     "
       
    82     "
       
    83      |f|
       
    84 
       
    85      f := #(1 2 3 4) asFloatArray.
       
    86      f *= #(1 2 3 4) asFloatArray.
       
    87      f     
       
    88     "
       
    89 !
       
    90 
       
    91 + anObject
    67 + anObject
    92     "return the sum of the receiver and the argument.
    68     "return the sum of the receiver and the argument.
    93      The argument may either be a scalar or another vector"
    69      The argument may either be a scalar or another vector"
    94 
    70 
    95     ^ self clone += anObject
    71     ^ self clone += anObject
    98      #(1 2 3 4) asFloatArray + 3      
    74      #(1 2 3 4) asFloatArray + 3      
    99      #(1 2 3 4) asFloatArray + #(1 2 3 4) asFloatArray  
    75      #(1 2 3 4) asFloatArray + #(1 2 3 4) asFloatArray  
   100     "
    76     "
   101 !
    77 !
   102 
    78 
   103 += anObject
       
   104     "add the argument into the receiver (destructive).
       
   105      The argument may either be a scalar or another vector"
       
   106 
       
   107     ^ anObject isNumber
       
   108             ifTrue:[self primAddScalar: anObject asFloat]
       
   109             ifFalse:[self primAddArray: anObject]
       
   110 
       
   111     "
       
   112      |f|
       
   113 
       
   114      f := #(1 2 3 4) asFloatArray.
       
   115      f += 3.
       
   116      f         
       
   117     "
       
   118     "
       
   119      |f|
       
   120 
       
   121      f := #(1 2 3 4) asFloatArray.
       
   122      f += #(1 2 3 4) asFloatArray.
       
   123      f      
       
   124     "
       
   125 !
       
   126 
       
   127 - anObject
    79 - anObject
   128     "return the difference of the receiver and the argument.
    80     "return the difference of the receiver and the argument.
   129      The argument may either be a scalar or another vector"
    81      The argument may either be a scalar or another vector"
   130 
    82 
   131     ^ self clone -= anObject
    83     ^ self clone -= anObject
   136     "
    88     "
   137 
    89 
   138     "Created: / 30-05-2007 / 17:41:46 / cg"
    90     "Created: / 30-05-2007 / 17:41:46 / cg"
   139 !
    91 !
   140 
    92 
   141 -= anObject
       
   142     "subtract the argument from the receiver (destructive).
       
   143      The argument may either be a scalar or another vector"
       
   144 
       
   145     ^ anObject isNumber
       
   146             ifTrue:[self primSubtractScalar: anObject asFloat]
       
   147             ifFalse:[self primSubtractArray: anObject]
       
   148 
       
   149     "
       
   150      |f|
       
   151 
       
   152      f := #(1 2 3 4) asFloatArray.
       
   153      f -= 3.
       
   154      f         
       
   155     "
       
   156     "
       
   157      |f|
       
   158 
       
   159      f := #(1 2 3 4) asFloatArray.
       
   160      f += #(1 2 3 4) asFloatArray.
       
   161      f      
       
   162     "
       
   163 
       
   164     "Created: / 30-05-2007 / 17:42:13 / cg"
       
   165 !
       
   166 
       
   167 / anObject
    93 / anObject
   168     "return the division of the receiver and the argument.
    94     "return the division of the receiver and the argument.
   169      The argument may either be a scalar or another vector"
    95      The argument may either be a scalar or another vector"
   170 
    96 
   171     ^ self clone /= anObject
    97     ^ self clone /= anObject
   174      #(1 2 3 4) asFloatArray / 3      
   100      #(1 2 3 4) asFloatArray / 3      
   175      #(1 2 3 4) asFloatArray / #(1 2 3 4) asFloatArray  
   101      #(1 2 3 4) asFloatArray / #(1 2 3 4) asFloatArray  
   176     "
   102     "
   177 
   103 
   178     "Created: / 30-05-2007 / 17:46:05 / cg"
   104     "Created: / 30-05-2007 / 17:46:05 / cg"
   179 !
       
   180 
       
   181 /= anObject
       
   182     "divide the argument into the receiver (destructive).
       
   183      The argument may either be a scalar or another vector"
       
   184 
       
   185     ^ anObject isNumber
       
   186         ifTrue:[self primDivScalar: anObject asFloat]
       
   187         ifFalse:[self primDivArray: anObject]
       
   188 
       
   189     "Modified: / 30-05-2007 / 17:45:46 / cg"
       
   190 !
   105 !
   191 
   106 
   192 abs
   107 abs
   193     ^ self clone primAbs
   108     ^ self clone primAbs
   194 
   109 
   577      f1 -= 2.
   492      f1 -= 2.
   578      Transcript showCR:f1.              
   493      Transcript showCR:f1.              
   579     "
   494     "
   580 
   495 
   581     "Created: / 30-05-2007 / 17:43:06 / cg"
   496     "Created: / 30-05-2007 / 17:43:06 / cg"
       
   497 ! !
       
   498 
       
   499 !FloatArray methodsFor:'arithmetic destructive'!
       
   500 
       
   501 *= anObject
       
   502     "multiply the argument into the receiver (destructive).
       
   503      The argument may either be a scalar or another vector"
       
   504 
       
   505     ^ anObject isNumber
       
   506             ifTrue:[self primMulScalar: anObject asFloat]
       
   507             ifFalse:[self primMulArray: anObject]
       
   508 
       
   509     "
       
   510      |f|
       
   511 
       
   512      f := #(1 2 3 4) asFloatArray.
       
   513      f *= 3.
       
   514      f         
       
   515     "
       
   516     "
       
   517      |f|
       
   518 
       
   519      f := #(1 2 3 4) asFloatArray.
       
   520      f *= #(1 2 3 4) asFloatArray.
       
   521      f     
       
   522     "
       
   523 !
       
   524 
       
   525 += anObject
       
   526     "add the argument into the receiver (destructive).
       
   527      The argument may either be a scalar or another vector"
       
   528 
       
   529     ^ anObject isNumber
       
   530             ifTrue:[self primAddScalar: anObject asFloat]
       
   531             ifFalse:[self primAddArray: anObject]
       
   532 
       
   533     "
       
   534      |f|
       
   535 
       
   536      f := #(1 2 3 4) asFloatArray.
       
   537      f += 3.
       
   538      f         
       
   539     "
       
   540     "
       
   541      |f|
       
   542 
       
   543      f := #(1 2 3 4) asFloatArray.
       
   544      f += #(1 2 3 4) asFloatArray.
       
   545      f      
       
   546     "
       
   547 !
       
   548 
       
   549 -= anObject
       
   550     "subtract the argument from the receiver (destructive).
       
   551      The argument may either be a scalar or another vector"
       
   552 
       
   553     ^ anObject isNumber
       
   554             ifTrue:[self primSubtractScalar: anObject asFloat]
       
   555             ifFalse:[self primSubtractArray: anObject]
       
   556 
       
   557     "
       
   558      |f|
       
   559 
       
   560      f := #(1 2 3 4) asFloatArray.
       
   561      f -= 3.
       
   562      f         
       
   563     "
       
   564     "
       
   565      |f|
       
   566 
       
   567      f := #(1 2 3 4) asFloatArray.
       
   568      f += #(1 2 3 4) asFloatArray.
       
   569      f      
       
   570     "
       
   571 
       
   572     "Created: / 30-05-2007 / 17:42:13 / cg"
       
   573 !
       
   574 
       
   575 /= anObject
       
   576     "divide the argument into the receiver (destructive).
       
   577      The argument may either be a scalar or another vector"
       
   578 
       
   579     ^ anObject isNumber
       
   580             ifTrue:[self primDivScalar: anObject asFloat]
       
   581             ifFalse:[self primDivArray: anObject]
       
   582 
       
   583     "Modified: / 30-05-2007 / 17:45:46 / cg"
   582 ! !
   584 ! !
   583 
   585 
   584 !FloatArray methodsFor:'copying'!
   586 !FloatArray methodsFor:'copying'!
   585 
   587 
   586 clone
   588 clone
   695      f2 := #(10 9 8 7 6) asFloatArray.
   697      f2 := #(10 9 8 7 6) asFloatArray.
   696      f1 replaceFrom:1 to:3 with:f2 startingAt:3       
   698      f1 replaceFrom:1 to:3 with:f2 startingAt:3       
   697     "
   699     "
   698 ! !
   700 ! !
   699 
   701 
       
   702 
       
   703 
   700 !FloatArray methodsFor:'queries'!
   704 !FloatArray methodsFor:'queries'!
   701 
   705 
   702 absMax
   706 absMax
   703     "return the largest absolute value"
   707     "return the largest absolute value"
   704 
   708 
   749 defaultElement
   753 defaultElement
   750     ^ ShortFloat zero
   754     ^ ShortFloat zero
   751 !
   755 !
   752 
   756 
   753 length
   757 length
   754     "Return the length of the receiver 
   758     "Return the length of the receiver interpreted as vector 
   755      (that is the length of teh vector from 0.0 @ 0.0 @ ... @ 0.0
   759      (that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0
   756       to the point in the n-dimensional space represented by the receiver)"
   760       to the point in the n-dimensional space represented by the receiver)"
   757 
   761 
   758     ^ self squaredLength sqrt
   762     ^ self squaredLength sqrt
   759 
   763 
   760     "
   764     "
   927      f1 := FloatArray withAll:#(5 4 3 2 1).
   931      f1 := FloatArray withAll:#(5 4 3 2 1).
   928      f1 minMax        
   932      f1 minMax        
   929     "
   933     "
   930 !
   934 !
   931 
   935 
       
   936 numFloats
       
   937     ^ self size
       
   938 !
       
   939 
   932 squaredLength
   940 squaredLength
   933     "Return the squared length of the receiver"
   941     "Return the squared length of the receiver interpreted as vector"
   934 
   942 
   935     ^ self dot: self
   943     ^ self dot: self
   936 ! !
   944 ! !
   937 
   945 
   938 !FloatArray methodsFor:'vector arithmetic'!
   946 !FloatArray methodsFor:'vector arithmetic'!
   984 ! !
   992 ! !
   985 
   993 
   986 !FloatArray class methodsFor:'documentation'!
   994 !FloatArray class methodsFor:'documentation'!
   987 
   995 
   988 version
   996 version
   989     ^ '$Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.25 2008-10-14 08:01:14 cg Exp $'
   997     ^ '$Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.26 2009-12-01 22:11:19 cg Exp $'
       
   998 !
       
   999 
       
  1000 version_CVS
       
  1001     ^ '$Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.26 2009-12-01 22:11:19 cg Exp $'
   990 ! !
  1002 ! !