normaliseSymbol method

Canonical normaliseSymbol(
  1. String indent,
  2. Symbol sym
)

Implementation

Canonical normaliseSymbol(String indent, Symbol sym) {
  final Canonical result =
      Canonical(UcumDecimal.fromString('1.000000000000000000000000000000'));

  if (sym.exponent != null) {
    if (sym.unit is BaseUnit) {
      result.units.add(CanonicalUnit(sym.unit! as BaseUnit, sym.exponent!));
    } else {
      final Canonical can =
          expandDefinedUnit(indent, sym.unit! as DefinedUnit);
      for (final CanonicalUnit c in can.units) {
        c.exponent = c.exponent * sym.exponent!;
      }
      result.units.addAll(can.units);
      if (sym.exponent! > 0) {
        for (int i = 0; i < sym.exponent!; i++) {
          result.value = result.value.multiply(can.value);
        }
      } else {
        for (int i = 0; i > sym.exponent!; i--) {
          result.value = result.value.divide(can.value);
        }
      }
    }
    if (sym.prefix != null) {
      if (sym.exponent! > 0) {
        for (int i = 0; i < sym.exponent!; i++) {
          result.value = sym.prefix?.value == null
              ? result.value
              : result.value.multiply(sym.prefix!.value);
        }
      } else {
        for (int i = 0; i > sym.exponent!; i--) {
          result.value = sym.prefix?.value == null
              ? result.value
              : result.value.divide(sym.prefix!.value);
        }
      }
    }
  }
  return result;
}