Class: Float

Inherits:
Object show all
Defined in:
lib/openc3/io/json_rpc.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.json_create(object) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/openc3/io/json_rpc.rb', line 83

def self.json_create(object)
  case object['raw']
  when "Infinity"  then  Float::INFINITY
  when "-Infinity" then -Float::INFINITY
  when "NaN"       then  Float::NAN
  end
end

Instance Method Details

#as_json(options = nil) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/openc3/io/json_rpc.rb', line 91

def as_json(options = nil)
  return { "json_class" => "Float", "raw" => "Infinity" }  if self.infinite? ==  1
  return { "json_class" => "Float", "raw" => "-Infinity" } if self.infinite? == -1
  return { "json_class" => "Float", "raw" => "NaN" }       if self.nan?

  return self
end