OxL Reference

method u8.checked_add

Checked addition: the sum, or none on overflow.

Example:

oxl✓ checked in CI
fn main() io {
  let max: u8 = 255
  let min: u8 = 0
  print("{max.checked_add(1)}")
  print("{(max - 1).checked_add(1)}")
}
Output
none
255
pub(api) fn checked_add(o: u8) -> u8?

Complexity. O(1).

Since. 1.0.0-beta

Parameters

NameType
ou8

Returns

u8?

Effects

none declared (pure unless the body says otherwise)

Defined in: std/core/numbers.oxl:3011

See also