Method: OpenC3::BinaryAccessor.get_check_overflow_ranges

Defined in:
lib/openc3/accessors/binary_accessor.rb

.get_check_overflow_ranges(bit_size, data_type) ⇒ Object



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/openc3/accessors/binary_accessor.rb', line 799

def self.get_check_overflow_ranges(bit_size, data_type)
  min_value = 0 # Default for UINT cases

  case bit_size
  when 8
    hex_max_value = MAX_UINT8
    if data_type == :INT
      min_value = MIN_INT8
      max_value = MAX_INT8
    else
      max_value = MAX_UINT8
    end
  when 16
    hex_max_value = MAX_UINT16
    if data_type == :INT
      min_value = MIN_INT16
      max_value = MAX_INT16
    else
      max_value = MAX_UINT16
    end
  when 32
    hex_max_value = MAX_UINT32
    if data_type == :INT
      min_value = MIN_INT32
      max_value = MAX_INT32
    else
      max_value = MAX_UINT32
    end
  when 64
    hex_max_value = MAX_UINT64
    if data_type == :INT
      min_value = MIN_INT64
      max_value = MAX_INT64
    else
      max_value = MAX_UINT64
    end
  else # Bitfield
    if data_type == :INT
      # Note signed integers must allow up to the maximum unsigned value to support values given in hex
      if bit_size > 1
        max_value = 2**(bit_size - 1)
        # min_value = -(2 ** bit_size - 1)
        min_value = -max_value
        # max_value = (2 ** bit_size - 1) - 1
        max_value -= 1
        # hex_max_value = (2 ** bit_size) - 1
        hex_max_value = (2**bit_size) - 1
      else # 1-bit signed
        min_value = -1
        max_value = 1
        hex_max_value = 1
      end
    else
      max_value = (2**bit_size) - 1
      hex_max_value = max_value
    end
  end

  return min_value, max_value, hex_max_value
end