aboutsummaryrefslogtreecommitdiff
path: root/src/String/String.h
blob: c947ea4b58281b94526f67e65e37dfcad114164a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef BH_STRING_STRING_H
#define BH_STRING_STRING_H


#include <BH/String.h>


#define BH_INT1120_DIGITS 70


typedef struct BH_Int1120
{
    int size;
    uint16_t digits[BH_INT1120_DIGITS];
} BH_Int1120;


/**
 * Counts the number of leading zero bits.
 *
 * \param value  Value
 *
 * \return Count of leading zeros.
 */
int BH_Int1120Clz(const uint16_t value);



/**
 * Compares big integers \a a and \a b.
 *
 * \param a  A integer
 * \param b  B integer
 *
 * \return Negative if \a a is less than \a b
 * \return Positive if \a a is greater than \a b
 * \return Zero if \a a and \a b are equal.
 */
int BH_Int1120Compare(const BH_Int1120 *a,
                      const BH_Int1120 *b);


/**
 * Adds two big integers \a a and \a b and stores result into \a out.
 *
 * \param a    A integer
 * \param b    B integer
 * \param out  Result integer
 */
void BH_Int1120Add(const BH_Int1120 *a,
                   const BH_Int1120 *b,
                   BH_Int1120 *out);


/**
 * Subtracts two big integers \a a and \a b and stores result into \a out.
 *
 * \param a    A integer
 * \param b    B integer
 * \param out  Result integer
 */
void BH_Int1120Sub(const BH_Int1120 *a,
                   const BH_Int1120 *b,
                   BH_Int1120 *out);


/**
 * Multiplies two big integers \a a and \a b and stores result into \a out.
 *
 * \param a    A integer
 * \param b    B integer
 * \param out  Result integer
 */
void BH_Int1120Mul(const BH_Int1120 *a,
                   const BH_Int1120 *b,
                   BH_Int1120 *out);


/**
 * Multiplies big integer \a a by \a digit and stores result into \a out.
 *
 * \param in     Input integer
 * \param digit  Digit
 * \param out    Result integer
 */
void BH_Int1120MulDigit(const BH_Int1120 *in,
                        uint16_t digit,
                        BH_Int1120 *out);


/**
 * Divides two big integers \a a and \a b and stores quotient into \a q and 
 * remainder into \a r.
 *
 * \param a  A integer
 * \param b  B integer
 * \param q  Output quotient integer
 * \param r  Output remainder integer
 */
void BH_Int1120Div(const BH_Int1120 *a,
                   const BH_Int1120 *b,
                   BH_Int1120 *q,
                   BH_Int1120 *r);


/**
 * Computes 10 to the power of \a exponent.
 *
 * \param exponent  Exponent
 * \param out       Result integer
 */
void BH_Int1120Pow10(int exponent,
                     BH_Int1120 *out);


/**
 * Multiplies a big integer \a in by 10 to the power of \a exponent.
 *
 * \param in        Input integer
 * \param exponent  Exponent
 * \param out       Result integer
 */
void BH_Int1120MulPow10(const BH_Int1120 *in,
                        int exponent,
                        BH_Int1120 *out);


/**
 * Computes 2 to the power of \a exponent.
 *
 * \param exponent  Exponent
 * \param out       Result integer
 */
void BH_Int1120Pow2(int exponent,
                    BH_Int1120 *out);


/**
 * Left shifts big integer \a in by \a amount places and stores result into 
 * \a out.
 *
 * \param in      Input integer
 * \param amount  Shift amount
 * \param out     Result integer
 */
void BH_Int1120Lsh(const BH_Int1120 *in,
                   int amount,
                   BH_Int1120 *out);


/**
 * Right shifts big integer \a in by \a amount places and stores result into
 * \a out.
 *
 * \param in      Input integer
 * \param amount  Shift amount
 * \param out     Result integer
 */
void BH_Int1120Rsh(const BH_Int1120 *in,
                   int amount,
                   BH_Int1120 *out);


#endif /* BH_STRING_STRING_H */