Conversion where both units (including compound units) are of precisely
 equivalent dimensions, i.e. direct alternatives for one another. Where
 previous unit is a compound unit, new unit must be cancelled by all original
 base units
353141
def convert_to_equivalent_unit!(new_unit)
      old_unit = @unit
      self.multiply!(Unit.ratio new_unit, old_unit)
      old_base_units = old_unit.base_units.map { |base| base.unit } if old_unit.is_compound_unit?
      self.cancel_base_units!(*old_base_units || [old_unit])
    end
1297249
def unit(self, unit):
        
        allowed_values = ["cm", "inch", "foot"]  # noqa: E501
        if unit is not None and unit not in allowed_values:
            raise ValueError(
                "Invalid value for `unit` ({0}), must be one of {1}"  # noqa: E501
                .format(unit, allowed_values)
            )

        self._unit = unit
46196
def convert_to_unit(self, unit):
        """"""
        self._values = self._header.data_type.to_unit(
            self._values, unit, self._header.unit)
        self._header._unit = unit
639635
def detailed_units(all_levels = false)
      mag = @magnitude
      prev_units = self.units
      units = {}
      loop do
        compound = false
        prev_units.each_pair do |dim, (unit,mul)|
          ud = Units.unit(unit)
          if ud.decomposition
            compound = true
            mag *= ud.decomposition.magnitude
            ud.decomposition.units.each_pair do |d, (u,m)|
              mag *= self.class.combine(units, d, u, m*mul)
            end
          else
            mag *= self.class.combine(units, dim, unit, mul)
          end
        end
        if all_levels && compound
          prev_units = units
          units = {}
        else
          break
        end
      end
      Measure.new mag, units
    end
133439
def swap(self, a, b):
        
        self.mem[a], self.mem[b] = self.mem[b], self.mem[a]
        self.asm[a], self.asm[b] = self.asm[b], self.asm[a]
190326
function(a, b, p, dir) {

      var s = this['SCALE'];
      a = mod(a, s);
      b = mod(b, s);

      if (a === b)
        return a;

      // dir becomes an offset if we have to add a full revolution (=scale)
      if (!dir)
        dir =-s;
      else if ((dir === 1) === (a < b))
        dir*= s;
      else
        dir = 0;

      return mod(a + p * (b - a - dir), s);
    }
1295095
def as_base_units(self):
        
        b = collections.defaultdict(int)
        factor = 1
        for k, v in self.items():
            derived = False
            for d in DERIVED_UNITS.values():
                if k in d:
                    for k2, v2 in d[k].items():
                        if isinstance(k2, Number):
                            factor *= k2 ** (v2 * v)
                        else:
                            b[k2] += v2 * v
                    derived = True
                    break
            if not derived:
                si, f = _get_si_unit(k)
                b[si] += v
                factor *= f ** v
        return {k: v for k, v in b.items() if v != 0}, factor
663904
@Override
  public UnitValue convert(UnitValue value, Unit target) {
    Unit src = value.unit();
    UnitCategory category = src.category();
    if (src == target || category != target.category()) {
      return value;
    }
    
    switch (category) {
      case CONCENTR:
      case LIGHT:
        // Not available
        break;

      case CONSUMPTION:
        return consumption(value, target);

      case TEMPERATURE:
        return temperature(value, target);
        
      case VOLUME:
        if (measurementSystem == MeasurementSystem.UK) {
          return convert(value, target, UnitFactors.VOLUME_UK);
        }
        return convert(value, target, UnitFactors.VOLUME);
        
      default:
        UnitFactorMap factors = FACTORS_MAP.get(category);
        if (factors != null) {
          return convert(value, target, factors);
        }
        break;
    }
    
    return value;
  }
466824
def swapWH(self):
        
        width = self.width
        self.width = self.height
        self.height = width
675270
def to_base_unit
      case @unit
      when :centimeter
        OoxmlSize.new(@value * 360_000)
      when :point
        OoxmlSize.new(@value * 12_700)
      when :half_point
        OoxmlSize.new(@value * (12_700 / 2))
      when :one_eighth_point
        OoxmlSize.new(@value * (12_700 / 8))
      when :one_100th_point
        OoxmlSize.new(@value * (12_700 / 100))
      when :one_240th_cm
        OoxmlSize.new(@value * 1500)
      when :dxa, :twip
        return OoxmlSize.new(@value * 635, :emu)
      when :inch
        OoxmlSize.new(@value * 914_400, :emu)
      when :spacing_point
        OoxmlSize.new(@value * (12_700 / 100), :emu)
      when :percent
        OoxmlSize.new(@value * 100_000, :one_100000th_percent)
      when :pct
        OoxmlSize.new(@value * 100_000 / 50, :one_100000th_percent)
      when :one_1000th_percent
        OoxmlSize.new(@value * 100, :one_100000th_percent)
      else
        self
      end
    end
1048866
def _preprocess(self, struct1, struct2, niggli=True):
        
        struct1 = struct1.copy()
        struct2 = struct2.copy()

        if niggli:
            struct1 = struct1.get_reduced_structure(reduction_algo="niggli")
            struct2 = struct2.get_reduced_structure(reduction_algo="niggli")

        # primitive cell transformation
        if self._primitive_cell:
            struct1 = struct1.get_primitive_structure()
            struct2 = struct2.get_primitive_structure()

        if self._supercell:
            fu, s1_supercell = self._get_supercell_size(struct1, struct2)
        else:
            fu, s1_supercell = 1, True
        mult = fu if s1_supercell else 1/fu

        # rescale lattice to same volume
        if self._scale:
            ratio = (struct2.volume / (struct1.volume * mult)) ** (1 / 6)
            nl1 = Lattice(struct1.lattice.matrix * ratio)
            struct1.lattice = nl1
            nl2 = Lattice(struct2.lattice.matrix / ratio)
            struct2.lattice = nl2

        return struct1, struct2, fu, s1_supercell
408776
def identical(self, a, b):
        
        return self._identical(self.convert(a), self.convert(b))
1224087
def to_si
      if @unit.is_compound_unit?
        Quantity.new(@value,@unit).convert_compound_unit_to_si!
      elsif @unit.is_dimensionless?
        return self.clone
      elsif @value.nil?
        return Quantity.new(nil, @unit.si_unit)
      else
        self.to(@unit.si_unit)
      end
    end
269477
def is_compatible(self, other):
        
        if isinstance(other, type(self)):
            # check step size, if possible
            try:
                if not self.dx == other.dx:
                    raise ValueError("%s sample sizes do not match: "
                                     "%s vs %s." % (type(self).__name__,
                                                    self.dx, other.dx))
            except AttributeError:
                raise ValueError("Series with irregular xindexes cannot "
                                 "be compatible")
            # check units
            if not self.unit == other.unit and not (
                    self.unit in [dimensionless_unscaled, None] and
                    other.unit in [dimensionless_unscaled, None]):
                raise ValueError("%s units do not match: %s vs %s."
                                 % (type(self).__name__, str(self.unit),
                                    str(other.unit)))
        else:
            # assume an array-like object, and just check that the shape
            # and dtype match
            arr = numpy.asarray(other)
            if arr.ndim != self.ndim:
                raise ValueError("Dimensionality does not match")
            if arr.dtype != self.dtype:
                warn("Array data types do not match: %s vs %s"
                     % (self.dtype, other.dtype))
        return True
438052
def units(self, val):
        """"""
        if isinstance(val, units.Unit):
            self._unit = val
        else:
            self._unit = units(val)
1221192
def inverse
      check_operable
      dims = dimension_uop{|a| -a}
      Unit.new(Rational(1,self.factor), dims)
    end
471183
def converted_value(other_unit)
      if other_unit.special?
        other_unit.magnitude scalar
      else
        scalar / other_unit.scalar
      end
    end