void *BucketAvg(bucketset_t set, char *name, void *value) { bucket_t *pbucket = DoFind(set, name); if (!pbucket) return NULL; if (pbucket->type == bt_int) return DoSet(pbucket, bint( AVG((*(int *)DoGet(pbucket)), (*(int *)value), pbucket->nvals))); if (pbucket->type == bt_float) return DoSet(pbucket, bfloat( AVG((*(double *)DoGet(pbucket)), (*(double *)value), pbucket->nvals))); //else, string -- just ignore return DoGet(pbucket); }
void *BucketAdd(bucketset_t set, char *name, void *value) { bucket_t *pbucket = DoFind(set, name); if (!pbucket) return NULL; if (pbucket->type == bt_int) return DoSet(pbucket, bint( (*(int *)DoGet(pbucket)) + (*(int *)value))); if (pbucket->type == bt_float) return DoSet(pbucket, bfloat( (*(double *)DoGet(pbucket)) + (*(double *)value))); //else, string -- just concat return BucketConcat(set, name, value); }
bint &operator-=(const bint &v) { if (sign == v.sign) { if (cmp(v, 0) != -1) { for (int i = 0, is = 0; i < (int)v.s.size() || is; i++) { s[i] -= is + (i < (int)v.s.size() ? v.s[i] : 0); if ((is = s[i] < 0)) { s[i] += BASE; } } trim(); return *this; } else { return *this = -(bint(v) -= *this); } } else { return *this += -v; } }
bint operator-(const bint &v)const { return bint(*this) -= v; }
bint operator+(const bint &v)const { return bint(*this) += v; }
bint operator*(const bint &v)const { return bint(*this) *= v; }