Class: RinRuby::R_Double
- Inherits:
-
R_DataType
- Object
- R_DataType
- RinRuby::R_Double
- Defined in:
- lib/rinruby.rb
Constant Summary collapse
- ID =
RinRuby_Type_Double
Class Method Summary collapse
Methods inherited from R_DataType
Class Method Details
.convertable?(value) ⇒ Boolean
725 726 727 728 729 |
# File 'lib/rinruby.rb', line 725 def convertable?(value) value.all?{|x| (x == nil) || x.kind_of?(Numeric) } end |
.receive(io) ⇒ Object
745 746 747 748 749 750 751 |
# File 'lib/rinruby.rb', line 745 def receive(io) length = io.read(4).unpack('l').first res = io.read(8 * length).unpack("D*") na_indices = io.read(4).unpack('l').first io.read(4 * na_indices).unpack("l*").each{|i| res[i] = nil} res end |
.send(value, io) ⇒ Object
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/rinruby.rb', line 730 def send(value, io) # Double format: data_size, data, ..., na_index_size, na_index, ... io.write([value.size].pack('l')) nils = [] value.each.with_index{|x, i| if x == nil then nils << i io.write([Float::NAN].pack('D')) else io.write([x.to_f].pack('D')) end } io.write(([nils.size] + nils).pack('l*')) value end |