Jūs esateŽurnalai / Ernestas Kardzys's blog / Compare two bignum'bers

Compare two bignum'bers


ParašėErnestas Kardzys - 2009 Gegužės 13

If you're working with bignum'bers, you'll probalby need to compare those two - are they equal, bigger, smaller etc. So, these functions might be useful:
bool equal(const bignum_t *a, const bignum_t *b) { if (a->sig_digits != b->sig_digits) return FALSE;    /* Not equal */ int i = 0; for (i = 0; i < a->sig_digits; i++) if (a->digits[i] != b->digits[i]) return FALSE;    /* Not equal */ return TRUE;    /* Equal */ } /* Checks if a is not equal to b */ bool nequal(const bignum_t *a, const bignum_t *b) { return !equal(a, b); } /* Checks if a < b */ bool less(const bignum_t *a, const bignum_t *b) { if (a->sig_digits > b->sig_digits) return FALSE;    /* Greater */ int i = 0; for (i = 0; i < a->sig_digits; i++) if (a->digits[i] > b->digits[i]) return FALSE;    /* Greater */ return TRUE;    /* Less */ } /* Checks if a > b */ bool greater(const bignum_t *a, const bignum_t *b) { return less(b, a); }

Skelbti naują komentarą

Šio laukelio turinys bus laikomas privatus ir nerodomas viešai.
  • Web puslapiu adresai ir el. pašto adresai automatiškai tampa nuorodomis.
  • Leidžiamos HTML žymės: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Linijos ir paragrafai atskiriami automatiškai
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

Daugiau informacijos apie teksto formatavimą

CAPTCHA
Šis klausimas yra skirtas įsitikinti, jog jūs esate žmogus, ir sustabdyti automatinį šlamšto siuntimą.