Your Search Results

    Float32Array Redirect 3

    The Float32Array type represents an array of 32-bit floating point numbers (corresponding to the C float data type) in the platform byte order. If control over byte order is needed, use DataView instead.

    Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).

    Constructors

    Note: In these methods, TypedArray represents any of the typed array object types.
    Float32Array Float32Array(unsigned long length);
    Float32Array Float32Array(TypedArray array);
    Float32Array Float32Array(sequence<type> array);
    Float32Array Float32Array(ArrayBuffer buffer, optional unsigned long byteOffset, optional unsigned long length);

    Method overview

    Note: In these methods, TypedArray represents any of the typed array object types.
    void set(TypedArray array, optional unsigned long offset);
    void set(type[] array, optional unsigned long offset);
    Float32Array subarray(long begin, optional long end);

    Attributes

    Attribute Type Description
    buffer ArrayBuffer The ArrayBuffer object used to contain the TypedArray datas. Read only.
    byteOffset unsigned long The index at wich starts the TypedArray in it underlying ArrayBufferRead only.
    length unsigned long The number of entries in the array. Read only.

    Constants

    Element size

    Constant Value Description
    BYTES_PER_ELEMENT 4 The size, in bytes, of each array element.

    Constructor

    Returns a new Float32Array object. Every entry in the array is initialized to 0 unless initial data is specifically provided.

    Float32Array Float32Array(
      unsigned long length
    );
    
    Float32Array Float32Array(
      TypedArray array
    );
    
    Float32Array Float32Array(
      sequence<type> array
    );
    
    Float32Array Float32Array(
      ArrayBuffer buffer,
      optional unsigned long byteOffset,
      optional unsigned long length
    );
    
    Parameters
    length
    The number of elements in the byte array. If unspecified, length of the array view will match the buffer's length.
    array
    An object of any of the typed array types (such as Uint8Array), or a sequence of objects of a particular type, to copy into a new ArrayBuffer. Each value in the source array is converted to a 32-bit floating point number before being copied into the new array.
    buffer
    An existing ArrayBuffer to use as the storage for the new Float32Array object.
    byteOffset
    The offset, in bytes, to the first byte in the specified buffer for the new view to reference. If not specified, the Float32Array's view of the buffer will start with the first byte.
    Return value

    A new Float32Array object representing the specified data buffer.

    Notes

    The first form of the constructor, accepting only a length, creates a new ArrayBuffer object that can hold the specified number of 32-bit floats, then creates and returns a typed array view referring to that new buffer. The length must be specified in this case.

    The second form creates a new ArrayBuffer object that is a duplicate of the specified array, except with each element in the new array converted to a 32-bit float.

    The third form of the constructor likewise creates a new ArrayBuffer object that is a duplicate of the specified JavaScript array, with each element in the new array converted to a 32-bit float.

    The final form of the constructor creates a new Float32Array object, using the specified ArrayBuffer as its storage. This lets you access the existing buffer in a different format. If specified, the byteOffset and length parameters let you create the new view to only a portion of the buffer.

    Exceptions thrown
    INDEX_SIZE_ERR
    The specified byteOffset isn't a multiple of the element size, or the byteOffset and length result in the specified view extending past the end of the buffer.

    Methods

    set()

    Sets multiple values in the typed array, reading input values from a specified array.

    void set(
      TypedArray array,
      optional unsigned long offset
    );
    
    void set(
      type[] array,
      optional unsigned long offset
    );
    
    Parameters
    array
    An array from which to copy values. All values from the source array are copied into the target array, unless the length of the source array plus the offset exceeds the length of the target array, in which case an exception is thrown. If the source array is a typed array, the two arrays may share the same underlying ArrayBuffer; the browser will intelligently copy the source range of the buffer to the destination range.
    offset Optional
    The offset into the target array at which to begin writing values from the source array. If you omit this value, 0 is assumed (that is, the source array will overwrite values in the target array starting at index 0).

    subarray()

    Returns a new Float32Array view on the ArrayBuffer store for this Float32Array object.

    Float32Array subarray(
      long begin,
      optional long end
    );
    
    Parameters
    begin
    The offset to the first element in the array to be referenced by the new Float32Array object.
    end Optional
    One more than the offset to the last element in the array to be referenced by the new Float32Array object. In other words, the new object will include elements from begin (inclusive) to end (exclusive). If not specified, all elements from the one specified by begin to the end of the array are included in the new view.
    Notes

    The range specified by begin and end is clamped to the valid index range for the current array; if the computed length of the new array would be negative, it's clamped to zero. If either begin or end is negative, it refers to an index from the end of the array instead of from the beginning.

    Note: Keep in mind that this is creating a new view on the existing buffer; changes to the new object's contents will impact the original object and vice versa.

    See also

    Document Tags and Contributors

    Contributors to this page: teoli
    Last updated by: teoli,