Module: Hornetseye::INT_::Match

Included in:
Node
Defined in:
lib/multiarray/int.rb

Overview

Namespace containing method for matching elements of type INT_

See Also:

Instance Method Summary collapse

Instance Method Details

#fit(*values) ⇒ Class

Method for matching elements of type INT_

Parameters:

  • *values (Array<Object>)

    Values to find matching native element type for.

Returns:

  • (Class)

    Native type fitting all values.

See Also:



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/multiarray/int.rb', line 244

def fit( *values )
  if values.all? { |value| value.is_a? Integer }
    bits = 8
    ubits = 8
    signed = false
    values.each do |value|
      bits *= 2 until ( -2**(bits-1) ... 2**(bits-1) ).include? value
      if value < 0
        signed = true
      else
        ubits *= 2 until ( 0 ... 2**ubits ).include? value
      end
    end
    bits = signed ? bits : ubits
    if bits <= 64
      Hornetseye::INT bits, signed
    else
      super *values
    end
  else
    super *values
  end
end