Class: KDL::Value::Float

Inherits:
KDL::Value show all
Defined in:
lib/kdl/value.rb

Direct Known Subclasses

KDL::V1::Value::Float

Constant Summary

Constants inherited from KDL::Value

Null

Instance Attribute Summary

Attributes inherited from KDL::Value

#format, #type, #value

Instance Method Summary collapse

Methods inherited from KDL::Value

#as_type, from, #initialize, #inspect, #method_missing, #respond_to_missing?, #to_s, #to_v2, #version

Constructor Details

This class inherits a constructor from KDL::Value

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KDL::Value

Instance Method Details

#==(other) ⇒ Object



75
76
77
78
79
80
# File 'lib/kdl/value.rb', line 75

def ==(other)
  return self == other.value if other.is_a?(Float)
  return other.nan? if value.nan?

  value == other
end

#stringify_valueObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/kdl/value.rb', line 82

def stringify_value
  return '#nan'  if value.nan?
  return '#inf'  if value == ::Float::INFINITY
  return '#-inf' if value == -::Float::INFINITY
  return super.upcase unless value.is_a?(BigDecimal)

  sign, digits, _, exponent = value.split
  s = +''
  s << '-' if sign.negative?
  s << "#{digits[0]}.#{digits[1..-1]}"
  s << "E#{exponent.negative? ? '' : '+'}#{exponent - 1}"
  s
end

#to_v1Object



96
97
98
99
100
101
# File 'lib/kdl/value.rb', line 96

def to_v1
  if value.nan? || value.infinite?
    warn "[WARNING] Converting non-finite Float to KDL v1"
  end
  V1::Value::Float.new(value, format:, type:)
end