decompressAmount static method

double decompressAmount(
  1. HermezCompressedAmount hermezCompressedAmount
)

Convert a HermezCompressedAmount to a fix @param {Scalar} fl - HermezCompressedAmount representation of the amount @returns {Scalar} Scalar encoded in fix

Implementation

static double decompressAmount(
    HermezCompressedAmount hermezCompressedAmount) {
  if (!HermezCompressedAmount.isHermezCompressedAmount(
      hermezCompressedAmount)) {
    throw new ArgumentError(
        'The parameter needs to be an instance of HermezCompressedAmount created with HermezCompressedAmount.compressAmount');
  }
  final fl = hermezCompressedAmount.value;
  final m = (fl % 0x800000000);
  final e = (fl / 0x800000000).floor();

  var exp = BigInt.from(1);
  for (var i = 0; i < e; i++) {
    exp *= BigInt.from(10);
  }

  final double res = m * exp.toDouble();

  return res;
}