Home / Docs / Standard library / Built-in methods

wrapping_shift_left

Release v0.4.0Edition 0.2 and later

A built-in method, resolved by the type of its receiver (spec/14 §2). Edition 0.2 and later.

una
a.wrapping_shift_left(by: Int) -> F
  where a: F, one of I8, I16, I32, I64, U8, U16, U32, U64

Requires 0 <= by and by below the width: a * 2^by reduced into the type's range modulo 2^w. There is no checked left shift (spec/18 §5).

Receiver

Parameters

Returns

F: a * 2^by reduced into the range of the type modulo 2^w, where w is its width: the bits shifted past the top are dropped.

Requires

Each condition under requires is an obligation at every call, which una check proves (spec/12 §3): it reports U5001 when the condition is refuted and U5002 when it is unknown (spec/12 §6), and una run, una test and una build refuse a package with an obligation that is not proved (spec/22 §2).

See also

shift_right

Example

src/shop.unauna
module shop

--- Values doubled and moved to the top bit, with the bits past the top dropped.
pub main() -> Unit
  uses @console: Console[print]
=
  let crates: U8 = 200
  let doubled = crates.wrapping_shift_left(by: 1)
  let one: I8 = 1
  let top = one.wrapping_shift_left(by: 7)
  @console.print("{doubled}")
  @console.print("{top}")

una run . prints:

Output
144
-128

Specification

Generated from una v0.4.0 (docs/std/builtins.json, which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: spec/14 §2.