Home / Docs / Standard library / Built-in methods
wrapping_add
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_add(by: F) -> F
where a: F, one of I8, I16, I32, I64, U8, U16, U32, U64Total: the exact result reduced into the type's range modulo 2^w, where w is its width (spec/18 §5).
Receiver
F, one of I8, I16, I32, I64, U8, U16, U32, U64: a fixed-width integera, of one of the eight typesI8,I16,I32,I64,U8,U16,U32andU64; the result has its type
Parameters
by: the other operand, of the same type
Returns
F: the exact sum reduced into the range of the type modulo 2^w, where w is its width: past the largest value it goes on from the smallest; it never fails.
See also
Example
src/shop.una
module shop
--- A one-byte ticket counter that goes on from the smallest value after the largest.
pub main() -> Unit
uses @console: Console[print]
=
let counter: U8 = 250
let next = counter.wrapping_add(by: 10)
let top: I8 = 127
let past = top.wrapping_add(by: 1)
@console.print("{next}")
@console.print("{past}")una run . prints:
Output
4
-128Specification
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.