<commit_before>class Numeric
  def undefined?
    false
  end

  def to_hex
    "0x#{to_s(16).upcase}"
  end

  def to_bin
    "0b#{to_s(2)}"
  end

  # Converts a number to a String representing binary number
  # Requires width of bit string for padding.  If the width is
  # less than the number of bits required to represent the number
  # the width argument is meaningless.
  def to_bitstring(width)
    '%0*b' % [width, self]
  end

  # Reverses the bit representation of a number and returns
  # the new value.  Useful when changing register data based on bit order
  def reverse_bits(width)
    result = 0
    0.upto(width - 1) do |i|
      result += self[i] * 2**(width - 1 - i)
    end
    result
  end

  def as_units(units)
    if self >= 1_000_000_000_000_000
      "#{self / 1_000_000_000_000_000.0}P#{units}"
    elsif self >= 1_000_000_000_000
      "#{self / 1_000_000_000_000.0}T#{units}"
    elsif self >= 1_000_000_000
      "#{self / 1_000_000_000.0}G#{units}"
    elsif self >= 1_000_000
      "#{self / 1_000_000.0}M#{units}"
    elsif self >= 1_000
      "#{self / 1_000.0}k#{units}"
    elsif self >= 1
      "#{self}#{units}"
    elsif self >= 1e-3
      "#{self * 1_000}m#{units}"
    elsif self >= 1e-6
      "#{self * 1_000_000}u#{units}"
    elsif self >= 1e-9
      "#{self * 1_000_000_000}n#{units}"
    elsif self >= 1e-12
      "#{self * 1_000_000_000_000}p#{units}"
    elsif self >= 1e-15
      "#{self * 1_000_000_000_000_000}a#{units}"
    else
      "%.3e#{units}" % self
    end
  end

  %w(Hz hz Ts ts bps sps ohm Ohm a A v V s S f F).each do |m|
    define_method "as_#{m}" do
      as_units(m)
    end
  end

  # Msps ==> Mega samples per second

  %w(GHz Ghz GTs Gts Gsps).each do |m|
    define_method m do
      self * 1_000_000_000
    end
  end

  %w(MHz Mhz MTs Mts Msps).each do |m|
    define_method m do
      self * 1_000_000
    end
  end

  %w(GB).each do |m|
    define_method m do
      self * 1_024 * 1_024 * 1_024
    end
  end

  %w(MB).each do |m|
    define_method m do
      self * 1_024 * 1_024
    end
  end

  %w(to_GB).each do |m|
    define_method m do
      result = self / 1_024 / 1_024 / 1_024
      if result == Integer(result)
        return Integer(result)
      else
        return result
      end
    end
  end
<commit_msg>Added in bits per second numeric extensions<commit_after>class Numeric
  def undefined?
    false
  end

  def to_hex
    "0x#{to_s(16).upcase}"
  end

  def to_bin
    "0b#{to_s(2)}"
  end

  # Converts a number to a String representing binary number
  # Requires width of bit string for padding.  If the width is
  # less than the number of bits required to represent the number
  # the width argument is meaningless.
  def to_bitstring(width)
    '%0*b' % [width, self]
  end

  # Reverses the bit representation of a number and returns
  # the new value.  Useful when changing register data based on bit order
  def reverse_bits(width)
    result = 0
    0.upto(width - 1) do |i|
      result += self[i] * 2**(width - 1 - i)
    end
    result
  end

  def as_units(units)
    if self >= 1_000_000_000_000_000
      "#{self / 1_000_000_000_000_000.0}P#{units}"
    elsif self >= 1_000_000_000_000
      "#{self / 1_000_000_000_000.0}T#{units}"
    elsif self >= 1_000_000_000
      "#{self / 1_000_000_000.0}G#{units}"
    elsif self >= 1_000_000
      "#{self / 1_000_000.0}M#{units}"
    elsif self >= 1_000
      "#{self / 1_000.0}k#{units}"
    elsif self >= 1
      "#{self}#{units}"
    elsif self >= 1e-3
      "#{self * 1_000}m#{units}"
    elsif self >= 1e-6
      "#{self * 1_000_000}u#{units}"
    elsif self >= 1e-9
      "#{self * 1_000_000_000}n#{units}"
    elsif self >= 1e-12
      "#{self * 1_000_000_000_000}p#{units}"
    elsif self >= 1e-15
      "#{self * 1_000_000_000_000_000}a#{units}"
    else
      "%.3e#{units}" % self
    end
  end

  %w(Hz hz Ts ts bps sps ohm Ohm a A v V s S f F).each do |m|
    define_method "as_#{m}" do
      as_units(m)
    end
  end

  # Msps ==> Mega samples per second

  %w(GHz Ghz GTs Gts Gsps Gbps).each do |m|
    define_method m do
      self * 1_000_000_000
    end
  end

  %w(MHz Mhz MTs Mts Msps Mbps).each do |m|
    define_method m do
      self * 1_000_000
    end
  end

  %w(GB).each do |m|
    define_method m do
      self * 1_024 * 1_024 * 1_024
    end
  end

  %w(MB).each do |m|
    define_method m do
      self * 1_024 * 1_024
    end
  end

  %w(to_GB).each do |m|
    define_method m do
      result = self / 1_024 / 1_024 / 1_024
      if result == Integer(result)
        return Integer(result)
      else
        return result
      end
    end
  end

{'fraction_non_alphanumeric': 0.11297973264338076, 'fraction_numerical': 0.098749460974558, 'mean_word_length': 2.320687186828919, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1857220', 'n_tokens_mistral': 2128, 'n_tokens_neox': 1838, 'n_words': 520}