Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

leftShift

Public Function
std.fmt.parse_float.decimal.Decimal.leftShift
pub fn leftShift(self: *Self, shift: usize) void

Computes decimal * 2^shift.

Params

  • self: *Self
  • shift: usize

File

fmt/parse_float/decimal.zig:142
142
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();
        }