module BSON::Float

def as_extended_json(**options)

Returns:
  • (Hash | Float) - The extended json representation.

Options Hash: (**opts)
  • :mode (nil | :relaxed | :legacy) -- Serialization mode
def as_extended_json(**options)
  if infinite? == 1
    { '$numberDouble' => 'Infinity' }
  elsif infinite? == -1
    { '$numberDouble' => '-Infinity' }
  elsif nan?
    { '$numberDouble' => 'NaN' }
  elsif options[:mode] == :relaxed || options[:mode] == :legacy
    self
  elsif BSON::Environment.jruby? && abs > 1e15
    # Hack to make bson corpus spec tests pass.
    # JRuby serializes -1.2345678901234568e+18 as
    # -1234567890123456770.0, which is valid but differs from MRI
    # serialization. Extended JSON spec does not define precise
    # stringification of floats.
    # https://jira.mongodb.org/browse/SPEC-1536
    { '$numberDouble' => ('%.17g' % to_s).upcase }
  else
    { '$numberDouble' => to_s.upcase }
  end
end

def to_bson(buffer = ByteBuffer.new)

Other tags:
    Since: - 2.0.0

Other tags:
    See: http://bsonspec.org/#/specification -

Returns:
  • (BSON::ByteBuffer) - The buffer with the encoded object.

Other tags:
    Example: Get the floating point as encoded BSON. -
def to_bson(buffer = ByteBuffer.new)
  buffer.put_double(self)
end