operator ^ method

Quantity operator ^(
  1. dynamic exponent
)

Returns this Quantity raised to the power of exponent.

  • This Quantity object is unaffected.
  • If the combined relative standard uncertainty of the resulting product Quantity is calculated it will be equal to the exponent times the relative standard uncertainty of this Quantity.

See NIST Reference on Constants, Units, and Uncertainty: Combining uncertainty components

Implementation

Quantity operator ^(dynamic exponent) {
  if (exponent == 1) return this;
  if (exponent == 0) {
    if (valueSI.toDouble() == 0) return Scalar(value: Double.NaN);
    return Scalar.one;
  }

  if (exponent is num) {
    return (dimensions ^ exponent).toQuantity(valueSI ^ exponent, null, _ur * exponent);
  } else if (exponent is Number) {
    return (dimensions ^ exponent.toDouble()).toQuantity(valueSI ^ exponent, null, _ur * exponent.toDouble());
  } else if (exponent is Scalar) {
    return (dimensions ^ exponent.valueSI.toDouble())
        .toQuantity(valueSI ^ exponent, null, _ur * exponent.valueSI.toDouble());
  }

  throw const QuantityException('Cannot raise a quantity to a non-numeric power');
}