本文整理汇总了C++中Num类的典型用法代码示例。如果您正苦于以下问题:C++ Num类的具体用法?C++ Num怎么用?C++ Num使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Num类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool operator<(const Num &a, const Num &b) {
if (a.size() != b.size()) {
return a.size() < b.size();
} else {
return a.repr < b.repr;
}
}
示例2: main
int main(){
Num a = 10 ;
Num b = 20 ;
Num c = a + b ;
c.print() ;
}
示例3: lcm
Num operator+(const Num& n) const
{
Num ret;
ret.b = lcm(n.b, b);
ret.a = (ret.b/b*a) + (ret.b/n.b*n.a);
ret.func();
return ret;
}
示例4: pow
Ex pow(const Ex & e, const Num & n)
{
if (n.isInt())
{
return pow(e, n.get_uint());
} else {
return pow(e, n);
}
}
示例5:
Num operator*(const Num& n) const
{
Num ret;
ret.b = n.b*b;
ret.a = n.a*a;
ret.func();
return ret;
}
示例6: Num
namespace thread {
class Num {
public:
Num() : m_num(0) {}
void Incr() {
m_lock.Lock();
++m_num;
m_lock.Unlock();
}
int GetNum() {
return m_num;
}
private:
int m_num;
CLock m_lock;
};
static Num num;
class IncrThread : public CThread {
public:
virtual void OnThreadRun() {
for (int i = 0; i < 1000; ++i) {
num.Incr();
}
}
};
}
示例7: max
const Num operator+(const Num &a, const Num &b) {
string res;
int len = max(a.size(), b.size());
string x = a.repr;
string y = b.repr;
reverse(x.begin(), x.end());
reverse(y.begin(), y.end());
x += string(len-x.size(), '0');
y += string(len-y.size(), '0');
int c = 0;
for (int i=0; i<len; ++i) {
int d = val[x[i]] + val[y[i]] + c;
res += dig[d%36];
c = (d>=36);
}
if (c) {
res += '1';
}
reverse(res.begin(), res.end());
return Num(res);
}
示例8: absolute
void absolute(var self) {
Num* inum = type_class(type_of(self), Num);
assert(inum->absolute);
inum->absolute(self);
}
示例9: Num
const type_ptr Num::operator / (Num& right) const
{
type_ptr res = new Num( value() / right.value() );
return res;
}
示例10: divide
void divide(var lhs, var rhs) {
Num* inum = type_class(type_of(lhs), Num);
assert(inum->div);
inum->div(lhs, rhs);
}
示例11: negate
void negate(var self) {
Num* inum = type_class(type_of(self), Num);
assert(inum->negate);
inum->negate(self);
}
示例12: mul
void mul(var lhs, var rhs) {
Num* inum = type_class(type_of(lhs), Num);
assert(inum->mul);
inum->mul(lhs, rhs);
}
示例13: sub
void sub(var lhs, var rhs) {
Num* inum = type_class(type_of(lhs), Num);
assert(inum->sub);
inum->sub(lhs, rhs);
}
示例14: main
int main() {
Num<int> left = -1;
Num<int> right = 1;
Num<int> result = left + right;
return result.get();
}
示例15: add
void add(var lhs, var rhs) {
Num* inum = type_class(type_of(lhs), Num);
assert(inum->add);
inum->add(lhs, rhs);
}