pub fn leftShift(self: *Self, shift: usize) void self: *Selfshift: usize142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183 pub fn leftShift(self: *Self, shift: usize) void {
if (self.num_digits == 0) {
return;
}
const num_new_digits = self.numberOfDigitsLeftShift(shift);
var read_index = self.num_digits;
var write_index = self.num_digits + num_new_digits;
var n: MantissaT = 0;
while (read_index != 0) {
read_index -= 1;
write_index -= 1;
n += math.shl(MantissaT, self.digits[read_index], shift);
const quotient = n / 10;
const remainder = n - (10 * quotient);
if (write_index < max_digits) {
self.digits[write_index] = @as(u8, @intCast(remainder));
} else if (remainder > 0) {
self.truncated = true;
}
n = quotient;
}
while (n > 0) {
write_index -= 1;
const quotient = n / 10;
const remainder = n - (10 * quotient);
if (write_index < max_digits) {
self.digits[write_index] = @as(u8, @intCast(remainder));
} else if (remainder > 0) {
self.truncated = true;
}
n = quotient;
}
self.num_digits += num_new_digits;
if (self.num_digits > max_digits) {
self.num_digits = max_digits;
}
self.decimal_point += @as(i32, @intCast(num_new_digits));
self.trim();
}
Computes decimal * 2^shift.