class Cborb::Decoding::Types::HalfPrecisionFloatingPoint
To represent part of major type: 7
@see tools.ietf.org/html/rfc7049#section-2.3 @see tools.ietf.org/html/rfc7049#appendix-D
Public Class Methods
decode(state, additional_info)
click to toggle source
# File lib/cborb/decoding/types/half_precision_floating_point.rb, line 8 def decode(state, additional_info) bits = state.consume(2).unpack("n".freeze).first bits = (bits & 0x7FFF) << 13 | (bits & 0x8000) << 16 fp = if (bits & 0x7C00) != 0x7C00 Math.ldexp(to_single(bits), 112) else to_single(bits | 0x7F800000) end state.accept_value(self, fp) end
Private Class Methods
to_single(bits)
click to toggle source
# File lib/cborb/decoding/types/half_precision_floating_point.rb, line 23 def to_single(bits) [bits].pack("N".freeze).unpack("g".freeze).first end