Returns a human readable representation of the units in this number.
 For complex units this takes the form of:
 numerator_unit1 * numerator_unit2 / denominator_unit1 * denominator_unit2
 @return [String] a string that represents the units in this number
6688
def unit_str
      rv = @numerator_units.sort.join("*")
      if @denominator_units.any?
        rv << "/"
        rv << @denominator_units.sort.join("*")
      end
      rv
    end
337751
def humanize_size(number)
      return nil if number.nil?

      if number.to_i < 1024
        unit = number > 1 ? 'Bytes' : 'Byte'
      else
        max_exp  = STORAGE_UNITS.size - 1
        number   = Float(number)
        exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024
        exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
        number  /= 1024**exponent
        unit = STORAGE_UNITS[exponent]
      end

      '%n %u'.gsub(/%n/, number.to_i.to_s).gsub(/%u/, unit)
    end
865154
def split_number_unit(string, strip_list=None):
    ''' 
        
    '''
    successFlag = True
    state = 0
    number_so_far = ""
    unit_so_far = ""
    decimal_found = False
    negate_flag = False
    if string is None:
        return (False, "", "")
    string = string.strip()
    if not strip_list:
        strip_list = []
    if len(string):
        if string[0]=="-":
            negate_flag = True
            string = string[1:]
    if len(string):
        if string[0]==".":
            string = "0"+string  # a string of ".12" is actually a legit number, but the lack of a preceding 0 will confuse python, so we tack on a zero
    if len(string):
        for char in string:
            if state==0:  # number state
                if char in ['0','1','2','3','4','5','6','7','8','9']:
                    number_so_far += char
                elif char in strip_list:
                    pass
                elif char==".":
                    if decimal_found:
                        successFlag = False # units do not begin with a period. ex: 234.2.anything 
                        state=2
                    else:
                        number_so_far += char
                        decimal_found = True
                elif char=="\n":
                    state=2
                else:
                    unit_so_far += char
                    state=1
            elif state==1: # unit state
                if char=="\n":
                    state=2
                elif char in strip_list:
                    pass
                else:
                    unit_so_far += char
            else: # discard state
                pass
        # clean up 
        unit_so_far = unit_so_far.strip()
        if len(number_so_far)==0:
            successFlag = False
        if negate_flag:
            number_so_far = "-"+number_so_far
        try:
            number_so_far = decimal.Decimal(number_so_far)
        except:
            successFlag = False
    else:
        successFlag = False
    if not successFlag:
        return(successFlag, "", unit_so_far)
    return (successFlag, number_so_far, unit_so_far)
808035
def digits
      digitstring = ''
      [:area_code, :prefix, :number].each {|part|
        digitstring += self.send(part).to_s unless self.send(part).nil?
      }
      digitstring += " x#{extension}" unless extension.nil?
      digitstring
    end
46944
def unit_signature_vector
      return to_base.unit_signature_vector unless base?
      vector = Array.new(SIGNATURE_VECTOR.size, 0)
      # it's possible to have a kind that misses the array... kinds like :counting
      # are more like prefixes, so don't use them to calculate the vector
      @numerator.map { |element| RubyUnits::Unit.definition(element) }.each do |definition|
        index = SIGNATURE_VECTOR.index(definition.kind)
        vector[index] += 1 if index
      end
      @denominator.map { |element| RubyUnits::Unit.definition(element) }.each do |definition|
        index = SIGNATURE_VECTOR.index(definition.kind)
        vector[index] -= 1 if index
      end
      raise ArgumentError, 'Power out of range (-20 < net power of a unit < 20)' if vector.any? { |x| x.abs >= 20 }
      vector
    end
617583
def str_numerator(self):
        """"""
        if not self.undefined:
            return None
        unit_numerator, unit = self._unit_class(self.numerator).auto
        formatter = '%d' if unit_numerator == self.numerator else '%0.2f'
        numerator = locale.format(formatter, unit_numerator, grouping=True)
        return '{0} {1}'.format(numerator, unit)
799422
def base?
      return @base if defined? @base
      @base = (@numerator + @denominator)
              .compact
              .uniq
              .map { |unit| RubyUnits::Unit.definition(unit) }
              .all? { |element| element.unity? || element.base? }
      @base
    end
816741
def get_symbol(units) -> str:
    
    if kind(units) == "energy":
        d = {}
        d["nm"] = r"\lambda"
        d["wn"] = r"\bar\nu"
        d["eV"] = r"\hslash\omega"
        d["Hz"] = r"f"
        d["THz"] = r"f"
        d["GHz"] = r"f"
        return d.get(units, "E")
    elif kind(units) == "delay":
        return r"\tau"
    elif kind(units) == "fluence":
        return r"\mathcal{F}"
    elif kind(units) == "pulse_width":
        return r"\sigma"
    elif kind(units) == "temperature":
        return r"T"
    else:
        return kind(units)
1255957
def get_number_of_atoms(self):
        
        strc = self.get_output_structure()
        if not strc:
            return None
        return Property(scalars=[Scalar(value=len(strc))], units="/unit cell")
52958
def _FormatSizeInUnitsOf1024(self, size):
    
    magnitude_1024 = 0
    used_memory_1024 = float(size)
    while used_memory_1024 >= 1024:
      used_memory_1024 /= 1024
      magnitude_1024 += 1

    if 0 < magnitude_1024 <= 7:
      return '{0:.1f} {1:s}'.format(
          used_memory_1024, self._UNITS_1024[magnitude_1024])

    return '{0:d} B'.format(size)
1337585
def read_units(self, fid):
        """"""
        lin = self.read_line(fid)                   
        while lin[0] != ':':
            parts = lin.split()
            if parts[0]=='mass':
                self.mass = float(parts[1])
            elif parts[0]=='length':
                self.length = float(parts[1])
            elif parts[0]=='angle':
                self.angle = parts[1]
            lin = self.read_line(fid)
        return lin
119181
def method_missing(method, *args, &block)
      if method.to_s =~ UNIT_LIST_REGEX

        if $2 || $4 || $6
          conditions = []

          conditions << "unit.is_#{$2}_unit?"     if $2
          conditions << "!unit.is_prefixed_unit?" if $4
          conditions << "unit.is_#{$6}_unit?"     if $6

          units = Unit.units.values.select { |unit| instance_eval(conditions.join(" && ")) }
        else
          units = Unit.units.values
        end

        return_format = ( $8 ? $8.to_sym : nil )
        units.map(&return_format).to_a
        
      elsif unit = Unit.for(method)

        return unit
      else

        super
      end
    end
1370367
def to_h(num, suffix='B'):
    """"""
    if num is None:  # Show None when data is missing
        return "None"
    for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
        if abs(num) < 1024.0:
            return "%3.1f%s%s" % (num, unit, suffix)
        num /= 1024.0
    return "%.1f%s%s" % (num, 'Yi', suffix)
160887
function writtenNumber(n, options) {
  options = options || {};
  options = util.defaults(options, writtenNumber.defaults);

  if (n < 0) {
    return "";
  }

  n = Math.round(+n);

  var language = typeof options.lang === "string"
    ? i18n[options.lang]
    : options.lang;

  if (!language) {
    if (languages.indexOf(writtenNumber.defaults.lang) < 0) {
      writtenNumber.defaults.lang = "en";
    }

    language = i18n[writtenNumber.defaults.lang];
  }
  
  var scale = language.useLongScale ? longScale : shortScale;
  var units = language.units;
  var unit;

  if (!(units instanceof Array)) {
    var rawUnits = units;

    units = [];
    scale = Object.keys(rawUnits);

    for (var i in scale) {
      units.push(rawUnits[scale[i]]);
      scale[i] = Math.pow(10, parseInt(scale[i]));
    }
  }

  var baseCardinals = language.base;
  var alternativeBaseCardinals = options.alternativeBase 
    ? language.alternativeBase[options.alternativeBase]
    : {};

  if (language.unitExceptions[n]) return language.unitExceptions[n];
  if (alternativeBaseCardinals[n]) return alternativeBaseCardinals[n];
  if (baseCardinals[n]) return baseCardinals[n];
  if (n < 100)
    return handleSmallerThan100(n, language, unit, baseCardinals, alternativeBaseCardinals, options);

  var m = n % 100;
  var ret = [];

  if (m) {
    if (
      options.noAnd &&
      !(language.andException && language.andException[10])
    ) {
      ret.push(writtenNumber(m, options));
    } else {
      ret.push(language.unitSeparator + writtenNumber(m, options));
    }
  }

  var firstSignificant;

  for (var i = 0, len = units.length; i < len; i++) {
    var r = Math.floor(n / scale[i]);
    var divideBy;

    if (i === len - 1) divideBy = 1000000;
    else divideBy = scale[i + 1] / scale[i];

    r %= divideBy;

    unit = units[i];

    if (!r) continue;
    firstSignificant = scale[i];

    if (unit.useBaseInstead) {
      var shouldUseBaseException =
        unit.useBaseException.indexOf(r) > -1 &&
        (unit.useBaseExceptionWhenNoTrailingNumbers
          ? i === 0 && ret.length
          : true);
      if (!shouldUseBaseException) {
        ret.push(alternativeBaseCardinals[r * scale[i]] || baseCardinals[r * scale[i]]);
      } else {
        ret.push(r > 1 && unit.plural ? unit.plural : unit.singular);
      }
      continue;
    }

    var str;
    if (typeof unit === "string") {
      str = unit;
    } else if (r === 1 || unit.useSingularEnding && r % 10 === 1
      && (!unit.avoidEndingRules || unit.avoidEndingRules.indexOf(r) < 0)) {
      str = unit.singular;
    } else if (unit.few && (r > 1 && r < 5 || unit.useFewEnding && r % 10 > 1 && r % 10 < 5
      && (!unit.avoidEndingRules || unit.avoidEndingRules.indexOf(r) < 0))) {
      str = unit.few;
    } else {
      str = unit.plural && (!unit.avoidInNumberPlural || !m)
        ? unit.plural
        : unit.singular;
      
      // Languages with dual
      str = (r === 2 && unit.dual) ? unit.dual : str;
      
      // "restrictedPlural" : use plural only for 3 to 10
      str = (r > 10 && unit.restrictedPlural) ? unit.singular : str;
    }

    if (
      unit.avoidPrefixException &&
      unit.avoidPrefixException.indexOf(r) > -1
    ) {
      ret.push(str);
      continue;
    }

    var exception = language.unitExceptions[r];
    var number =
      exception ||
      writtenNumber(
        r,
        util.defaults(
          {
            // Languages with and exceptions need to set `noAnd` to false
            noAnd: !((language.andException && language.andException[r]) ||
              unit.andException) && true,
            alternativeBase: unit.useAlternativeBase
          },
          options
        )
      );
    n -= r * scale[i];
    ret.push(number + " " + str);
  }

  var firstSignificantN = firstSignificant * Math.floor(n / firstSignificant);
  var rest = n - firstSignificantN;

  if (
    language.andWhenTrailing &&
    firstSignificant &&
    0 < rest &&
    ret[0].indexOf(language.unitSeparator) !== 0
  ) {
    ret = [ret[0], language.unitSeparator.replace(/\s+$/, "")].concat(
      ret.slice(1)
    );
  }
  
  // Languages that have separators for all cardinals.
  if (language.allSeparator) {
    for (var j = 0; j < ret.length-1; j++) {
      ret[j] = language.allSeparator + ret[j];      
    }
  }
  var result = ret.reverse().join(" ");
  return result;
}
457964
def units(self) -> typing.Iterator['BaseUnit']:
        
        for unit_index in self._section_group['units']:
            if unit_index not in self.__units.keys():
                _category = self.units_class_enum[self.group_category]  # type: ignore
                self.__units[unit_index] = _category(self.d, self.l10n, self.coa_color,
                                                     self.country_index,
                                                     self.group_category,
                                                     self.group_index, unit_index)
            yield self.__units[unit_index]
557032
def to_hash
      h = super
      h['timed_stats'] = @timed_stats.to_hash
      h['value_stats'] = @value_stats.to_hash( Stats::STATS - %w[ rate ] )
      h['rate'] = self.rate
      h['unit_count'] = self.unit_count
      return h
    end
680418
def format_num(num, unit='bytes'):
    
    if unit == 'bytes':
        extension = 'B'
    else:
        # if it's not bytes, it's bits
        extension = 'Bit'
    for dimension in (unit, 'K', 'M', 'G', 'T'):
        if num < 1024:
            if dimension == unit:
                return '%3.1f %s' % (num, dimension)
            return '%3.1f %s%s' % (num, dimension, extension)
        num /= 1024
    return '%3.1f P%s' % (num, extension)