Class: Cborb::Decoding::Types::HalfPrecisionFloatingPoint

Inherits:
Type
  • Object
show all
Defined in:
lib/cborb/decoding/types/half_precision_floating_point.rb

Overview

To represent part of major type: 7

Class Method Summary collapse

Methods inherited from Type

accept, indefinite?

Class Method Details

.decode(state, additional_info) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# 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