Skip to content

Commit

Permalink
int64 to bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Aug 21, 2024
1 parent ac03ac5 commit ecac253
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/provable/int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,14 +1147,22 @@ class Int64 extends CircuitValue implements BalanceChange {
return Int64.create(UInt64.from(obj.magnitude), Sign.fromValue(obj.sgn));
}

/**
* Turns the {@link Int64} into a {@link BigInt}.
*/
toBigint() {
let abs = this.magnitude.toBigInt();
let sgn = this.sgn.isPositive().toBoolean() ? 1n : -1n;
return sgn * abs;
}

/**
* Turns the {@link Int64} into a string.
*/
toString() {
let abs = this.magnitude.toString();
let sgn = this.isPositive().toBoolean() || abs === '0' ? '' : '-';
return sgn + abs;
return this.toBigint().toString();
}

isConstant() {
return this.magnitude.value.isConstant() && this.sgn.isConstant();
}
Expand Down

0 comments on commit ecac253

Please sign in to comment.