]>
Dogcows Code - chaz/tar/blob - src/arith.h
1 /* Simple arithmetic for numbers greater than a long int, for GNU tar.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Also, see comments at beginning of arith.c. */
20 #define BITS_PER_BYTE 8 /* number of bits in each sizeof unit */
21 #define BITS_PER_TARLONG 42 /* wanted number of bits in each tarlong */
23 /* In all cases, tarlong is the proper type for a big number.
25 For simulated arithmetic, SUPERDIGIT is the base, TARLONG_FORMAT is the
26 format to print a single super-digit filled with zeroes to the left, and
27 BITS_PER_SUPERDIGIT is the smallest number of bits required to fully
28 represent each super-digit. LONGS_PER_TARLONG says how many longs are
29 required for a full tarlong, and SIZEOF_TARLONG is the size of a tarlong
32 For straight compiler arithmetic, SUPERDIGIT is zero and TARLONG_FORMAT
33 is the format to directly print a tarlong (without zero-filling).
35 The values of SIZEOF_LONG_LONG and SIZEOF_UNSIGNED_LONG, below, are
36 obtained through the configuration process. */
38 #if BITS_PER_BYTE * SIZEOF_UNSIGNED_LONG >= BITS_PER_TARLONG
40 # define TARLONG_FORMAT "%uld"
41 typedef unsigned long tarlong
;
43 # if BITS_PER_BYTE * SIZEOF_LONG_LONG >= BITS_PER_TARLONG + 1
45 # define TARLONG_FORMAT "%lld"
46 typedef long long tarlong
;
48 # if BITS_PER_BYTE * SIZEOF_UNSIGNED_LONG >= 64
49 # define SUPERDIGIT 1000000000L
50 # define BITS_PER_SUPERDIGIT 29
51 # define TARLONG_FORMAT "%09uld"
53 # if BITS_PER_BYTE * SIZEOF_UNSIGNED_LONG >= 32
54 # define SUPERDIGIT 10000L
55 # define BITS_PER_SUPERDIGIT 14
56 # define TARLONG_FORMAT "%04uld"
64 # define LONGS_PER_TARLONG \
65 ((BITS_PER_TARLONG + BITS_PER_SUPERDIGIT - 1) / BITS_PER_SUPERDIGIT)
66 # define SIZEOF_TARLONG (LONGS_PER_TARLONG * sizeof (unsigned long))
68 /* The NEC EWS 4.2 C compiler gets confused by a pointer to a typedef that
69 is an array. So we wrap the array into a struct. (Pouah!) */
73 unsigned long digit
[LONGS_PER_TARLONG
];
76 typedef struct tarlong tarlong
;
78 int zerop_tarlong_helper
PARAMS ((unsigned long *));
79 int lessp_tarlong_helper
PARAMS ((unsigned long *, unsigned long *));
80 void clear_tarlong_helper
PARAMS ((unsigned long *));
81 void add_to_tarlong_helper
PARAMS ((unsigned long *, int));
82 void mult_tarlong_helper
PARAMS ((unsigned long *, int));
83 void print_tarlong_helper
PARAMS ((unsigned long *, FILE *));
85 # define zerop_tarlong(Accumulator) \
86 zerop_tarlong_helper (&(Accumulator).digit[0])
88 # define lessp_tarlong(First, Second) \
89 lessp_tarlong_helper (&(First).digit[0], &(Second).digit[0])
91 # define clear_tarlong(Accumulator) \
92 clear_tarlong_helper (&(Accumulator).digit[0])
94 # define add_to_tarlong(Accumulator, Value) \
95 add_to_tarlong_helper (&(Accumulator).digit[0], (Value))
97 # define mult_tarlong(Accumulator, Value) \
98 mult_tarlong_helper (&(Accumulator).digit[0], (Value))
100 # define print_tarlong(Accumulator, File) \
101 print_tarlong_helper (&(Accumulator).digit[0], (File))
103 #else /* not SUPERDIGIT */
105 # define zerop_tarlong(Accumulator) \
108 # define lessp_tarlong(First, Second) \
111 # define clear_tarlong(Accumulator) \
114 # define add_to_tarlong(Accumulator, Value) \
115 ((Accumulator) += (Value))
117 # define mult_tarlong(Accumulator, Value) \
118 ((Accumulator) *= (Value))
120 # define print_tarlong(Accumulator, File) \
121 (fprintf ((File), TARLONG_FORMAT, (Accumulator)))
123 #endif /* not SUPERDIGIT */
This page took 0.037483 seconds and 4 git commands to generate.