Class: Yadriggy::C::FloatArray

Inherits:
FFIArray
  • Object
show all
Defined in:
lib/yadriggy/c/ffi.rb

Overview

Array of 64bit floating point numbers. In C, the type of this array is arrayof(Float).

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FFIArray

#==, #length, #memory_pointer, #set_values, #size, #to_a

Constructor Details

#initialize(size, ptr = nil) ⇒ FloatArray

Returns a new instance of FloatArray.

Parameters:

  • size (Integer)

    array size.

  • ptr (FFI::MemoryPointer) (defaults to: nil)

    a memory pointer or nil. If nil, a new memory block is allocated.



84
85
86
87
88
89
90
# File 'lib/yadriggy/c/ffi.rb', line 84

def initialize(size, ptr=nil)
  if ptr.nil?
    @array = FFI::MemoryPointer.new(:double, size)
  else
    @array = ptr
  end
end

Class Method Details

.element_typeObject



100
101
102
# File 'lib/yadriggy/c/ffi.rb', line 100

def self.element_type()
  Float
end

Instance Method Details

#[](index) ⇒ Object



92
93
94
# File 'lib/yadriggy/c/ffi.rb', line 92

def [](index)
  @array.get_float64(index * 8)
end

#[]=(index, value) ⇒ Object



96
97
98
# File 'lib/yadriggy/c/ffi.rb', line 96

def []=(index, value)
  @array.put_float64(index * 8, value)
end