本文整理匯總了TypeScript中@ktn/rational.Rational類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Rational類的具體用法?TypeScript Rational怎麽用?TypeScript Rational使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Rational類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: calc
/**
* @method Add#calc
* @return {Rational}
*/
public calc(): Rational {
let v: Rational = Rational.zero;
for (const item of this._items) {
if (typeof (item.calc) === 'function') {
v = v.add(item.calc());
} else {
v = v.add(Rational.str(`${item}`));
}
}
return v;
}
示例2: calc
/**
* @method Div#calc
* @return {Rational}
*/
public calc(): Rational {
let v: Rational = Rational.one;
let isFirst: boolean = true;
for (const item of this._items) {
if (isFirst) {
isFirst = false;
v = (typeof (item.calc) === 'function') ? item.calc() : Rational.str(`${item}`);
continue;
}
if (typeof (item.calc) === 'function') {
v = v.div(item.calc());
} else {
v = v.div(Rational.str(`${item}`));
}
}
return v;
}
示例3: inv
/**
* @return {Mul}
*/
public inv(): Mul {
const a: any[] = [];
for (let item of this._items) {
let b: any = typeof (item.clone) !== 'undefined' ? item.clone() : item;
a.push(typeof (b.inv) !== 'undefined' ? b.inv() : Rational.str(`1/${b}`));
}
return new Mul(a);
}
示例4: calc
/**
* @return {?}
*/
public calc(): any {
let a: any = this._a;
let p: any = this._p;
if (typeof (a.calc) === 'function') {
a = a.calc();
} else {
a = Rational.str(`${a}`);
}
if (typeof (p.calc) === 'function') {
p = p.calc();
} else {
p = parseFloat(p);
}
return a.pow(p);
}
示例5: sub
/**
* @method Add.sub
* @param {...?} items
* @return {Add}
*/
public static sub(...items: any[]): Add {
const l: int = items.length;
if (l === 0) {
return new Add([]);
}
const n: any = [items[0]];
for (let i: int = 1; i < l; ++i) {
let item: any = items[i];
if (typeof (item.neg) === 'function') {
item = item.neg();
} else {
item = Rational.str(`${-item}`);
}
n.push(item);
}
return new Add(n);
}