From 1e1e70d9a6dbe00583a4a8f538d4786d30309482 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Wed, 14 Aug 2013 17:11:30 -0700 Subject: [PATCH] Add Amount#invert. --- src/js/ripple/amount.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/js/ripple/amount.js b/src/js/ripple/amount.js index 2f3c671e..441bde90 100644 --- a/src/js/ripple/amount.js +++ b/src/js/ripple/amount.js @@ -556,6 +556,21 @@ Amount.prototype.negate = function () { return this.clone('NEGATE'); }; +/** + * Invert this amount and return the new value. + * + * Creates a new Amount object as a copy of the current one (including the same + * unit (currency & issuer), inverts it (1/x) and returns the result. + */ +Amount.prototype.invert = function () { + var one = this.clone(); + one._value = BigInteger.ONE; + one._offset = 0; + one._is_negative = false; + one.canonicalize(); + return one.ratio_human(this); +}; + /** * Tries to correctly interpret an amount as entered by a user. *