]> gitweb.factorcode.org Git - factor.git/blob - vm/bignum.hpp
Merge branch 'redis' of git://www.tiodante.com/git/factor
[factor.git] / vm / bignum.hpp
1 namespace factor
2 {
3
4 /* :tabSize=2:indentSize=2:noTabs=true:
5
6 Copyright (C) 1989-1992 Massachusetts Institute of Technology
7 Portions copyright (C) 2004-2009 Slava Pestov
8
9 This material was developed by the Scheme project at the Massachusetts
10 Institute of Technology, Department of Electrical Engineering and
11 Computer Science.  Permission to copy and modify this software, to
12 redistribute either the original software or a modified version, and
13 to use this software for any purpose is granted, subject to the
14 following restrictions and understandings.
15
16 1. Any copy made of this software must include this copyright notice
17 in full.
18
19 2. Users of this software agree to make their best efforts (a) to
20 return to the MIT Scheme project any improvements or extensions that
21 they make, so that these may be included in future releases; and (b)
22 to inform MIT of noteworthy uses of this software.
23
24 3. All materials developed as a consequence of the use of this
25 software shall duly acknowledge such use, in accordance with the usual
26 standards of acknowledging credit in academic research.
27
28 4. MIT has made no warrantee or representation that the operation of
29 this software will be error-free, and MIT is under no obligation to
30 provide any services, by way of maintenance, update, or otherwise.
31
32 5. In conjunction with products arising from the use of this material,
33 there shall be no use of the name of the Massachusetts Institute of
34 Technology nor of any adaptation thereof in any advertising,
35 promotional, or sales literature without prior written consent from
36 MIT in each case. */
37
38 #define BIGNUM_OUT_OF_BAND ((bignum *) 0)
39
40 enum bignum_comparison
41 {
42   bignum_comparison_equal = 0,
43   bignum_comparison_less = -1,
44   bignum_comparison_greater = 1
45 };
46
47 int bignum_equal_p(bignum *, bignum *);
48 enum bignum_comparison bignum_compare(bignum *, bignum *);
49 bignum * bignum_add(bignum *, bignum *);
50 bignum * bignum_subtract(bignum *, bignum *);
51 bignum * bignum_negate(bignum *);
52 bignum * bignum_multiply(bignum *, bignum *);
53 void
54 bignum_divide(bignum * numerator, bignum * denominator,
55                   bignum * * quotient, bignum * * remainder);
56 bignum * bignum_quotient(bignum *, bignum *);
57 bignum * bignum_remainder(bignum *, bignum *);
58 bignum * fixnum_to_bignum(fixnum);
59 bignum * cell_to_bignum(cell);
60 bignum * long_long_to_bignum(s64 n);
61 bignum * ulong_long_to_bignum(u64 n);
62 fixnum bignum_to_fixnum(bignum *);
63 cell bignum_to_cell(bignum *);
64 s64 bignum_to_long_long(bignum *);
65 u64 bignum_to_ulong_long(bignum *);
66 bignum * double_to_bignum(double);
67 double bignum_to_double(bignum *);
68
69 /* Added bitwise operators. */
70
71 bignum * bignum_bitwise_not(bignum *);
72 bignum * bignum_arithmetic_shift(bignum *, fixnum);
73 bignum * bignum_bitwise_and(bignum *, bignum *);
74 bignum * bignum_bitwise_ior(bignum *, bignum *);
75 bignum * bignum_bitwise_xor(bignum *, bignum *);
76
77 /* Forward references */
78 int bignum_equal_p_unsigned(bignum *, bignum *);
79 enum bignum_comparison bignum_compare_unsigned(bignum *, bignum *);
80 bignum * bignum_add_unsigned(bignum *, bignum *, int);
81 bignum * bignum_subtract_unsigned(bignum *, bignum *);
82 bignum * bignum_multiply_unsigned(bignum *, bignum *, int);
83 bignum * bignum_multiply_unsigned_small_factor
84   (bignum *, bignum_digit_type, int);
85 void bignum_destructive_scale_up(bignum *, bignum_digit_type);
86 void bignum_destructive_add(bignum *, bignum_digit_type);
87 void bignum_divide_unsigned_large_denominator
88   (bignum *, bignum *, bignum * *, bignum * *, int, int);
89 void bignum_destructive_normalization(bignum *, bignum *, int);
90 void bignum_destructive_unnormalization(bignum *, int);
91 void bignum_divide_unsigned_normalized(bignum *, bignum *, bignum *);
92 bignum_digit_type bignum_divide_subtract
93   (bignum_digit_type *, bignum_digit_type *, bignum_digit_type,
94    bignum_digit_type *);
95 void bignum_divide_unsigned_medium_denominator
96   (bignum *, bignum_digit_type, bignum * *, bignum * *, int, int);
97 bignum_digit_type bignum_digit_divide
98   (bignum_digit_type, bignum_digit_type, bignum_digit_type, bignum_digit_type *);
99 bignum_digit_type bignum_digit_divide_subtract
100   (bignum_digit_type, bignum_digit_type, bignum_digit_type, bignum_digit_type *);
101 void bignum_divide_unsigned_small_denominator
102   (bignum *, bignum_digit_type, bignum * *, bignum * *, int, int);
103 bignum_digit_type bignum_destructive_scale_down
104   (bignum *, bignum_digit_type);
105 bignum * bignum_remainder_unsigned_small_denominator
106   (bignum *, bignum_digit_type, int);
107 bignum * bignum_digit_to_bignum(bignum_digit_type, int);
108 bignum * allot_bignum(bignum_length_type, int);
109 bignum * allot_bignum_zeroed(bignum_length_type, int);
110 bignum * bignum_shorten_length(bignum *, bignum_length_type);
111 bignum * bignum_trim(bignum *);
112 bignum * bignum_new_sign(bignum *, int);
113 bignum * bignum_maybe_new_sign(bignum *, int);
114 void bignum_destructive_copy(bignum *, bignum *);
115
116 /* Added for bitwise operations. */
117 bignum * bignum_magnitude_ash(bignum * arg1, fixnum n);
118 bignum * bignum_pospos_bitwise_op(int op, bignum *, bignum *);
119 bignum * bignum_posneg_bitwise_op(int op, bignum *, bignum *);
120 bignum * bignum_negneg_bitwise_op(int op, bignum *, bignum *);
121 void        bignum_negate_magnitude(bignum *);
122
123 bignum * bignum_integer_length(bignum * arg1);
124 int bignum_unsigned_logbitp(int shift, bignum * bignum);
125 int bignum_logbitp(int shift, bignum * arg);
126 bignum * digit_stream_to_bignum(unsigned int n_digits,
127                                    unsigned int (*producer)(unsigned int),
128                                    unsigned int radix,
129                                    int negative_p);
130
131 }