本文整理汇总了TypeScript中bignumber.js.default.minus方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.default.minus方法的具体用法?TypeScript js.default.minus怎么用?TypeScript js.default.minus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bignumber.js.default
的用法示例。
在下文中一共展示了js.default.minus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: denormalizePrice
export function denormalizePrice(minPrice: string|number|BigNumber, maxPrice: string|number|BigNumber, normalizedPrice: string|number|BigNumber): BigNumber {
const bnMinPrice: BigNumber = new BigNumber(minPrice, 10);
const bnMaxPrice: BigNumber = new BigNumber(maxPrice, 10);
const bnNormalizedPrice: BigNumber = new BigNumber(normalizedPrice, 10);
if (bnMinPrice.gt(bnMaxPrice)) throw new Error("Minimum value larger than maximum value");
if (bnNormalizedPrice.lt(0)) throw new Error("Normalized price is below 0");
if (bnNormalizedPrice.gt(1)) throw new Error("Normalized price is above 1");
return bnNormalizedPrice.times(bnMaxPrice.minus(bnMinPrice)).plus(bnMinPrice);
}
示例2: BigNumber
new BigNumber(0).lt(x) // true
new BigNumber(11.1, 2).lt(11, 3) // true
}
{
0.1 <= (0.3 - 0.2) // false
const x = new BigNumber(0.1)
x.lessThanOrEqualTo(new BigNumber(0.3).minus(0.2)) // true
new BigNumber(-1).lte(x) // true
new BigNumber(10, 18).lte('i', 36) // true
}
{
0.3 - 0.1 // 0.19999999999999998
const x = new BigNumber(0.3)
x.minus(0.1) // '0.2'
x.minus(0.6, 20) // '0'
}
{
1 % 0.9 // 0.09999999999999998
const x = new BigNumber(1)
x.modulo(0.9) // '0.1'
const y = new BigNumber(33)
y.mod('a', 33) // '3'
}
{
const x = new BigNumber(1.8)
x.negated() // '-1.8'
const y = new BigNumber(-1.3)
示例3: numTicksToTickSize
export function numTicksToTickSize(numTicks: BigNumber, minPrice: BigNumber, maxPrice: BigNumber): BigNumber {
return maxPrice.minus(minPrice).dividedBy(numTicks);
}
示例4: BigNumber
.spread(function(addressDetails, feeDetails, serverDetails, keys) {
const openLedgerFee = new BigNumber(feeDetails.body.result.drops.open_ledger_fee);
const baseReserve = new BigNumber(serverDetails.body.result.info.validated_ledger.reserve_base_xrp).times(self.getBaseFactor());
const reserveDelta = new BigNumber(serverDetails.body.result.info.validated_ledger.reserve_inc_xrp).times(self.getBaseFactor());
const currentLedger = serverDetails.body.result.info.validated_ledger.seq;
const sequenceId = addressDetails.body.result.account_data.Sequence;
const balance = new BigNumber(addressDetails.body.result.account_data.Balance);
const signerLists = addressDetails.body.result.account_data.signer_lists;
const accountFlags = addressDetails.body.result.account_data.Flags;
// make sure there is only one signer list set
if (signerLists.length !== 1) {
throw new Error('unexpected set of signer lists');
}
// make sure the signers are user, backup, bitgo
const userAddress = rippleKeypairs.deriveAddress(keys[0].getPublicKeyBuffer().toString('hex'));
const backupAddress = rippleKeypairs.deriveAddress(keys[1].getPublicKeyBuffer().toString('hex'));
const signerList = signerLists[0];
if (signerList.SignerQuorum !== 2) {
throw new Error('invalid minimum signature count');
}
const foundAddresses = {};
const signerEntries = signerList.SignerEntries;
if (signerEntries.length !== 3) {
throw new Error('invalid signer list length');
}
for (const { SignerEntry } of signerEntries) {
const weight = SignerEntry.SignerWeight;
const address = SignerEntry.Account;
if (weight !== 1) {
throw new Error('invalid signer weight');
}
// if it's a dupe of an address we already know, block
if (foundAddresses[address] >= 1) {
throw new Error('duplicate signer address');
}
foundAddresses[address] = (foundAddresses[address] || 0) + 1;
}
if (foundAddresses[userAddress] !== 1) {
throw new Error('unexpected incidence frequency of user signer address');
}
if (foundAddresses[backupAddress] !== 1) {
throw new Error('unexpected incidence frequency of user signer address');
}
// make sure the flags disable the master key and enforce destination tags
const USER_KEY_SETTING_FLAG = 65536;
const MASTER_KEY_DEACTIVATION_FLAG = 1048576;
const REQUIRE_DESTINATION_TAG_FLAG = 131072;
if ((accountFlags & USER_KEY_SETTING_FLAG) !== 0) {
throw new Error('a custom user key has been set');
}
if ((accountFlags & MASTER_KEY_DEACTIVATION_FLAG) !== MASTER_KEY_DEACTIVATION_FLAG) {
throw new Error('the master key has not been deactivated');
}
if ((accountFlags & REQUIRE_DESTINATION_TAG_FLAG) !== REQUIRE_DESTINATION_TAG_FLAG) {
throw new Error('the destination flag requirement has not been activated');
}
// recover the funds
const reserve = baseReserve.plus(reserveDelta.times(5));
const recoverableBalance = balance.minus(reserve);
const rawDestination = params.recoveryDestination;
const destinationDetails = url.parse(rawDestination);
const queryDetails = querystring.parse(destinationDetails.query);
const destinationAddress = destinationDetails.pathname;
let destinationTag = undefined;
if (Array.isArray(queryDetails.dt)) {
// if queryDetails.dt is an array, that means dt was given multiple times, which is not valid
throw new InvalidAddressError(`destination tag can appear at most once, but ${queryDetails.dt.length} destination tags were found`);
}
const parsedTag = parseInt(queryDetails.dt, 10);
if (Number.isInteger(parsedTag)) {
destinationTag = parsedTag;
}
const transaction = {
TransactionType: 'Payment',
Account: params.rootAddress, // source address
Destination: destinationAddress,
DestinationTag: destinationTag,
Amount: recoverableBalance.toFixed(0),
Flags: 2147483648,
LastLedgerSequence: currentLedger + 1000000, // give it 1 million ledgers' time (~1 month, suitable for KRS)
Fee: openLedgerFee.times(3).toFixed(0), // the factor three is for the multisigning
Sequence: sequenceId
};
const txJSON = JSON.stringify(transaction);
if (isUnsignedSweep) {
return txJSON;
}
//.........这里部分代码省略.........
示例5: percentageDiff
* between
*
* @param {string|BigNumber} newNum The new number
* @param {string|BigNumber} oldNum The old number
* @returns {{ diff: string; increase: boolean }}
*/
percentageDiff(
newNum: string | BigNumber,
oldNum: string | BigNumber,
): { diff: string; increase: boolean } {
const newNumBig = new BigNumber(newNum);
const oldNumBig = new BigNumber(oldNum);
if (newNumBig.eq(oldNumBig)) {
return { diff: "0", increase: false };
} else if (newNumBig.comparedTo(oldNumBig) > 0) {
const inc = newNumBig.minus(oldNumBig);
return {
increase: true,
diff: inc
.div(oldNumBig)
.times(100)
.toString(),
};
} else {
const dec = oldNumBig.minus(newNumBig);
return {
increase: false,
diff: dec
.div(oldNumBig)
.times(100)
.toString(),