本文整理汇总了C++中DIGIT函数的典型用法代码示例。如果您正苦于以下问题:C++ DIGIT函数的具体用法?C++ DIGIT怎么用?C++ DIGIT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DIGIT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mp_get_double
static MVMnum64 mp_get_double(mp_int *a) {
MVMnum64 d = 0.0;
MVMnum64 sign = SIGN(a) == MP_NEG ? -1.0 : 1.0;
int i;
if (USED(a) == 0)
return d;
if (USED(a) == 1)
return sign * (MVMnum64) DIGIT(a, 0);
mp_clamp(a);
i = USED(a) - 1;
d = (MVMnum64) DIGIT(a, i);
i--;
if (i == -1) {
return sign * d;
}
d *= pow(2.0, DIGIT_BIT);
d += (MVMnum64) DIGIT(a, i);
if (USED(a) > 2) {
i--;
d *= pow(2.0, DIGIT_BIT);
d += (MVMnum64) DIGIT(a, i);
}
d *= pow(2.0, DIGIT_BIT * i);
return sign * d;
}
示例2: GREADR
void GREADR(Word *a_, Word *t_)
{
Word C,S,a,t;
/* hide algorithm */
Step1: /* Skip blanks and read sign, if any. */
t = 1; S = 1;
C = CREADB();
if (C == '+')
C = CREADB();
else if (C == '-')
{ C = CREADB(); S = -1; }
if (DIGIT(C) == 0)
{ SWRITE("Error GREADR: A digit was expected.\n"); goto Step3; }
Step2: /* Read digits and convert. */
a = 0;
do
{ a = 10 * a + C - '0'; C = CREAD(); }
while (!(DIGIT(C) == 0));
BKSP(); a = S * a; goto Return;
Step3: /* Error. */
DIELOC(); t = 0; goto Return;
Return: /* Prepare for return. */
*a_ = a;
*t_ = t;
return;
}
示例3: speaknum
void speaknum(int n)
{
int buf[20], len = 0;
if (n % 10) buf[len++] = DIGIT(n % 10);
n /= 10;
if (n > 0) {
buf[len++] = TEN;
if (n % 10 > 1) buf[len++] = DIGIT(n % 10);
n /= 10;
if (n > 0) {
buf[len++] = HUNDRED;
if (n % 10 > 1) buf[len++] = DIGIT(n % 10);
n /= 10;
if (n > 0) {
buf[len++] = THOUSAND;
if (n % 10 > 1) buf[len++] = DIGIT(n % 10);
n /= 10;
if (n > 0) {
buf[len++] = TENTHOUSAND;
if (n % 10 > 1) buf[len++] = DIGIT(n % 10);
}
}
}
}
speak(YANG);
while (len--) speak(buf[len]);
speak(MARI);
}
示例4: get_lowest_permutation
cube_number_t get_lowest_permutation(cube_number_t number){
cube_number_t i, old = number;
for (i = 10; i < old;i *=10) {
for(cube_number_t scale = 10; scale < old; scale *= 10)
if (DIGIT(number, scale) > DIGIT(number, scale/10))
number = SWITCH_DIGIT(number, scale);
}
return number+i;
}
示例5: store_bigint_result
/* Stores an bigint in a bigint result body, either as a 32-bit smallint if it
* is in range, or a big integer if not. Clears and frees the passed bigint if
* it is not being used. */
static void store_bigint_result(MVMP6bigintBody *body, mp_int *i) {
if (can_be_smallint(i)) {
body->u.smallint.flag = MVM_BIGINT_32_FLAG;
body->u.smallint.value = SIGN(i) ? -DIGIT(i, 0) : DIGIT(i, 0);
mp_clear(i);
MVM_free(i);
}
else {
body->u.bigint = i;
}
}
示例6: vtest
/* do the test on the 2 vectors */
static int
vtest(arr_t *lhs, int tst, arr_t *rhs)
{
int cmp;
unsigned int c, i;
for (i = 0, c = MAX(lhs->c, rhs->c) ; i < c ; i++) {
if ((cmp = DIGIT(lhs->v, lhs->c, i) - DIGIT(rhs->v, rhs->c, i)) != 0) {
return result(cmp, tst);
}
}
return result(lhs->revision - rhs->revision, tst);
}
示例7: match
bool match(char* P, char* T) {
size_t m = strlen(P), n = strlen(T);
HashCode Dm, hashP = 0, hashT = 0;
Dm = prepareDm(m);
for (size_t i = 0; i < m; i++) {
hashP = (hashP*R + DIGIT(P, i)) % M;
hashT = (hashT*R + DIGIT(T, i)) % M;
}
for (size_t k = 0;;) {
if (hashT == hashP && check1by1(P, T, k)) return true;
if (++k>n - m) return false;
else updateHash(hashT, T, m, k, Dm);
}
}
示例8: parse
// Convert a version number string to an array of integers
// 12.34.56 -> 56
// "12.34" -> 34
// 19" -> 19
int parse (char *str, int *result)
{
int len, i;
char *t, *s, *e, *u;
if (!str)
exit (-1);
len = strlen (str);
if (len < 1)
return 0;
// Start at end: scan backwards for end of number
e = str + len;
for (t = e - 1; t >= str; t--)
if (DIGIT(*t))
break;
// Failed?
if (t < str)
{
printf ("Can't find a number in %s\n", str);
exit (-1);
}
// Now scan back further for start of number, but allow punctuation.
for (s=t, t=t-1; t >= str; s=t--)
if (!VERNUM(*t))
break;
#ifdef DEBUG
printf ("So far, e=%s t=%s s=%s\n", e, t, s);
#endif
// If first char is not a digit, move forward: ex: joe-1.2 would stop
// on - between joe and 1. Move forward over it
for (;s<e && PUNCT(*s); s++)
;
#ifdef DEBUG
printf ("finally str='%s' s='%s'\n", str, s);
#endif
// Now, pull them out, one by one
for (u=s, i=0; i<MAX_COMPONENTS; i++)
{
char *v = u;
long l = strtol (v, &u, 10);
if (u==v)
{
// No more chars we can parse
break;
}
// Accept number
result[i] = l;
#ifdef DEBUG
printf ("r[%d]=%d\n", i, result[i]);
#endif
// Skip over punctuation
for (u++; u<e && PUNCT(*u); u++)
;
}
return i;
}
示例9: two_complement_bitop
static void two_complement_bitop(mp_int *a, mp_int *b, mp_int *c,
int (*mp_bitop)(mp_int *, mp_int *, mp_int *)) {
mp_int d;
if (SIGN(a) ^ SIGN(b)) {
/* exactly one of them is negative, so need to perform
* some magic. tommath stores a sign bit, but Perl 6 expects
* 2's complement */
mp_init(&d);
if (MP_NEG == SIGN(a)) {
grow_and_negate(a, USED(b), &d);
mp_bitop(&d, b, c);
} else {
grow_and_negate(b, USED(a), &d);
mp_bitop(a, &d, c);
}
if (DIGIT(c, USED(c) - 1) & ((mp_digit)1<<(mp_digit)(DIGIT_BIT - 1))) {
grow_and_negate(c, c->used, &d);
mp_copy(&d, c);
mp_neg(c, c);
}
mp_clear(&d);
} else {
mp_bitop(a, b, c);
}
}
示例10: is_numeric
spocp_result_t
is_numeric(octet_t *op, long *num)
{
char *sp;
size_t l;
long n;
if (op->val == 0 || *(op->val) == 0)
return SPOCP_SYNTAXERROR;
for ( n = 0L, l = 0, sp = op->val ; l < op->len && DIGIT(*sp) ; l++,sp++) {
if (n)
n *= 10;
n += *sp -'0' ;
}
if (n == LONG_MIN || n == LONG_MAX)
return SPOCP_SYNTAXERROR;
if (l == op->len) {
*num = n;
return SPOCP_SUCCESS;
} else
return SPOCP_SYNTAXERROR;
}
示例11: sum_number
node* sum_number(node *a, node *b){
char sum, carry;
node *head, *end;
// sum each digit
for(head=end=new_digit(-1), sum=carry=0; a || b; a=NEXT(a), b=NEXT(b)){
sum = DIGIT(a) + DIGIT(b) + carry;
carry = sum>9;
end = end->next = new_digit(sum % 10);
}
// add extra digit when applicable
if(carry) end->next = new_digit(carry);
// delete first dummy node
a = head->next;
free(head);
return a;
}
示例12: from_num
static void from_num(MVMnum64 d, mp_int *a) {
MVMnum64 d_digit = pow(2, DIGIT_BIT);
MVMnum64 da = fabs(d);
MVMnum64 upper;
MVMnum64 lower;
MVMnum64 lowest;
MVMnum64 rest;
int digits = 0;
mp_zero(a);
while (da > d_digit * d_digit * d_digit) {;
da /= d_digit;
digits++;
}
mp_grow(a, digits + 3);
/* populate the top 3 digits */
upper = da / (d_digit*d_digit);
rest = fmod(da, d_digit*d_digit);
lower = rest / d_digit;
lowest = fmod(rest,d_digit );
if (upper >= 1) {
mp_set_long(a, (unsigned long) upper);
mp_mul_2d(a, DIGIT_BIT , a);
DIGIT(a, 0) = (mp_digit) lower;
mp_mul_2d(a, DIGIT_BIT , a);
} else {
if (lower >= 1) {
mp_set_long(a, (unsigned long) lower);
mp_mul_2d(a, DIGIT_BIT , a);
a->used = 2;
} else {
a->used = 1;
}
}
DIGIT(a, 0) = (mp_digit) lowest;
/* shift the rest */
mp_mul_2d(a, DIGIT_BIT * digits, a);
if (d < 0)
mp_neg(a, a);
mp_clamp(a);
mp_shrink(a);
}
示例13: mpl_bit_set
mp_err mpl_bit_set(mp_int *a, int bit)
{
unsigned int ddigit,bbit;
mp_err res;
//int bob;
ARGCHK(a != NULL, MP_BADARG);
//bob=DIGIT_BIT;
ddigit = bit / DIGIT_BIT;
bbit = bit % DIGIT_BIT;
if((res = s_mp_pad(a,ddigit+1)) != MP_OKAY)
return res;
DIGIT(a, ddigit) = DIGIT(a, ddigit) | (1 << bbit);
return MP_OKAY;
}
示例14: mp_get_int64
/* A forced 64-bit version of mp_get_long, since on some platforms long is
* not all that long. */
static MVMuint64 mp_get_int64(mp_int * a) {
int i;
MVMuint64 res;
if (a->used == 0) {
return 0;
}
/* get number of digits of the lsb we have to read */
i = MIN(a->used,(int)((sizeof(MVMuint64)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
/* get most significant digit of result */
res = DIGIT(a,i);
while (--i >= 0) {
res = (res << DIGIT_BIT) | DIGIT(a,i);
}
return res;
}
示例15: mpl_bit_clear
mp_err mpl_bit_clear(mp_int *a, int bit)
{
unsigned int ddigit,bbit;
ARGCHK(a != NULL, MP_BADARG);
ddigit = bit / DIGIT_BIT;
bbit = bit % DIGIT_BIT;
if( ddigit >= USED(a) ) //il faut clear un bit déjà clear...
return MP_OKAY;
DIGIT(a, ddigit) = DIGIT(a, ddigit) & ~(1 << bbit);
//Enleve les espace inutiles si requis
s_mp_clamp(a)
return MP_OKAY;
}