eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'DoubleArray':



Class: DoubleArray



rev: 1.34 date: 2019/07/19 15:25:51
user: cg
file: DoubleArray.st directory: libbasic
module: stx stc-classLibrary: libbasic
Claus Gittinger


DoubleArrays store doubleFloat values (and nothing else).
They have been added to support heavy duty number crunching and
data exchange with openGL frameworks and other mass data libraries
somewhat better than other smalltalks do. 
Storing Floats & Doubles in these objects (instead of Arrays)
has some benefits:

1) since the values are stored directly (instead of pointers to them)
   both access overhead and garbage collect overhead is minimized.

2) they can be much faster passed to c functions (such as graphics 
   libraries or heavy duty math packages), since the double values
   come packed and can be used in C by using a (double *) or double[].
   There is no need to loop over the array extracting doubles.      

3) they could (in theory) be much more easily be processed by things like
   vector and array processors

Be aware however, that Float- and DoubleArrays are not supported in other
smalltalks - your program will thus become somewhat less portable.
(since their protocol is the same as normal arrays filled with floats,
 they can of course be easily simulated - a bit slower though)

However, they could be simulated by a ByteArray, using doubleAt: and 
doubleAtPut: messages to access the elements, but that seems a bit
clumsy and unelegant. Also, the stc-compiler may learn how to deal
with Float- and DoubleArrays, making accesses very fast in the future.
Hint: if you use doubleArrays in your application and must port it
to some other smalltalk, define a DoubleArray class there, which is derived
from ByteArray, and add access methods.

Of course, DoubleArray can be subclassed,
and named instance variables can be added there.

See example uses in the GLX interface and GLDemos.

[memory requirements:]
    OBJ-HEADER + (size * double-size)

Related information:


Class protocol:

o  elementByteSize
for bit-like containers, return the number of bytes stored per element.
Here, 8 is returned

o  epsilon
return the maximum relative spacing of my elements
(i.e. the value-delta of the least significant bit)

o  precision
answer the precision (the number of bits in the mantissa) of my elements (in bits)
This is an IEEE halffloat, where only the fraction from the normalized mantissa is stored
and so there is a hidden bit and the mantissa is actually represented by 53 binary digits
(although only 52 are needed in the binary representation)

Instance protocol:

o  defaultElement

o  isValidElement: anObject
return true, if I can hold this kind of object

o  max
return the largest element;
redefined for speed

o  min
return the smallest element;
redefined for speed

o  minMax
return a Tuple holding the smallest and largest element;
redefined for speed

o  isFloatArray
return true if the receiver has float elements.
These are Float, Double- and HalfFloat arrays

vector arithmetic
o  dot: aFloatVector
Return the dot product of the receiver and the argument.
Raises an error, if the argument is not of the same size as the receiver.

o  esum
Return the sum of the elements.
Reduces accumulated rounding errors.
This is an experimental algorithm

o  hornerMultiplyAndAdd: x
primitive support for horner's-method computation of polynomials.
The vector is interpreted as providing the factors for a polynomial,
an*x^n + (an-1)*x^(n-1) + ... + a2(x) + a1
where the ai are the elements of the Array.
The highest rank factor is at the first position, the 0-rank constant at last.
This is inlined c-code, which may get compiled to fast machine code,
using multiply-and-add or vector instructions, if the CPU/Compiler support them.

o  sum
Return the sum of the elements.
May suffer from accumulated rounding error

ST/X; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 22 Feb 2024 18:48:54 GMT