void hd_sparse(DSS_HUGE i, DSS_HUGE *ok, long seq) { long low_mask, seq_mask; static int init = 0; static DSS_HUGE *base, *res; if (init == 0) { INIT_HUGE(base); INIT_HUGE(res); init = 1; } low_mask = (1 << SPARSE_KEEP) - 1; seq_mask = (1 << SPARSE_BITS) - 1; bin_bcd2(i, base, base + 1); HUGE_SET (base, res); HUGE_DIV (res, 1 << SPARSE_KEEP); HUGE_MUL (res, 1 << SPARSE_BITS); HUGE_ADD (res, seq, res); HUGE_MUL (res, 1 << SPARSE_KEEP); HUGE_ADD (res, *base & low_mask, res); bcd2_bin (&low_mask, *res); bcd2_bin (&seq_mask, *(res + 1)); *ok = low_mask; *(ok + 1) = seq_mask; return; }
long bcd2_cmp(long *low1, long *high1, long comp) { long temp = 0; bcd2_bin(&temp, *high1); if (temp > 214) return(1); bcd2_bin(&temp, *low1); return(temp - comp); }
main() { long bin, low_bcd, high_bcd; int i; bin = MAXINT; printf("%ld\n", bin); bin_bcd2(bin, &low_bcd, &high_bcd); printf("%ld %ld\n", high_bcd, low_bcd); bin = 0; bcd2_bin(&bin, high_bcd); bcd2_bin(&bin, low_bcd); printf( "%ld\n", bin); for (i=9; i >= 0; i--) printf("%dth digit in %d is %d\n", i, bin, GET_DIGIT(i, low_bcd, high_bcd)); bcd2_add(&low_bcd, &high_bcd, MAXINT); bin = 0; bcd2_bin(&bin, high_bcd); high_bcd = bin; bin = 0; bcd2_bin(&bin, low_bcd); low_bcd = bin; printf( "%ld%07ld\n", high_bcd, low_bcd); bin_bcd2(14, &low_bcd, &high_bcd); bcd2_mul(&low_bcd, &high_bcd, 23L); bin = 0; bcd2_bin(&bin, high_bcd); bcd2_bin(&bin, low_bcd); printf( "%ld\n", bin); bcd2_div(&low_bcd, &high_bcd, 10L); bin = 0; bcd2_bin(&bin, high_bcd); bcd2_bin(&bin, low_bcd); printf( "%ld\n", bin); }