math::checked+x86_64 +linux

math::checked provides safe integer arithmetic functions that check for overflow.

The functions add*, sub* and mul* perform wrapping integer arithmetic, with the same semantics as the +, -, and * operators.

const (res, overflow) = math::addi32(types::I32_MAX, 1);
assert(res == types::I32_MIN);
assert(overflow);

The functions sat_* perform saturating integer arithmetic, which clamp the result value to the range of the type.

const res = math::sat_addi32(types::I32_MAX, 1);
assert(res == types::I32_MAX);

Index

Functions

fn addi(a: int, b: int) (int, bool);
fn addi16(a: i16, b: i16) (i16, bool);
fn addi32(a: i32, b: i32) (i32, bool);
fn addi64(a: i64, b: i64) (i64, bool);
fn addi8(a: i8, b: i8) (i8, bool);
fn addu(a: uint, b: uint) (uint, bool);
fn addu16(a: u16, b: u16) (u16, bool);
fn addu32(a: u32, b: u32) (u32, bool);
fn addu64(a: u64, b: u64) (u64, bool);
fn addu8(a: u8, b: u8) (u8, bool);
fn addz(a: size, b: size) (size, bool);
fn muli(a: int, b: int) (int, bool);
fn muli16(a: i16, b: i16) (i16, bool);
fn muli32(a: i32, b: i32) (i32, bool);
fn muli64(a: i64, b: i64) (i64, bool);
fn muli8(a: i8, b: i8) (i8, bool);
fn mulu(a: uint, b: uint) (uint, bool);
fn mulu16(a: u16, b: u16) (u16, bool);
fn mulu32(a: u32, b: u32) (u32, bool);
fn mulu64(a: u64, b: u64) (u64, bool);
fn mulu8(a: u8, b: u8) (u8, bool);
fn mulz(a: size, b: size) (size, bool);
fn sat_addi(a: int, b: int) int;
fn sat_addi16(a: i16, b: i16) i16;
fn sat_addi32(a: i32, b: i32) i32;
fn sat_addi64(a: i64, b: i64) i64;
fn sat_addi8(a: i8, b: i8) i8;
fn sat_addu(a: uint, b: uint) uint;
fn sat_addu16(a: u16, b: u16) u16;
fn sat_addu32(a: u32, b: u32) u32;
fn sat_addu64(a: u64, b: u64) u64;
fn sat_addu8(a: u8, b: u8) u8;
fn sat_addz(a: size, b: size) size;
fn sat_muli(a: int, b: int) int;
fn sat_muli16(a: i16, b: i16) i16;
fn sat_muli32(a: i32, b: i32) i32;
fn sat_muli64(a: i64, b: i64) i64;
fn sat_muli8(a: i8, b: i8) i8;
fn sat_mulu(a: uint, b: uint) uint;
fn sat_mulu16(a: u16, b: u16) u16;
fn sat_mulu32(a: u32, b: u32) u32;
fn sat_mulu64(a: u64, b: u64) u64;
fn sat_mulu8(a: u8, b: u8) u8;
fn sat_mulz(a: size, b: size) size;
fn sat_subi(a: int, b: int) int;
fn sat_subi16(a: i16, b: i16) i16;
fn sat_subi32(a: i32, b: i32) i32;
fn sat_subi64(a: i64, b: i64) i64;
fn sat_subi8(a: i8, b: i8) i8;
fn sat_subu(a: uint, b: uint) uint;
fn sat_subu16(a: u16, b: u16) u16;
fn sat_subu32(a: u32, b: u32) u32;
fn sat_subu64(a: u64, b: u64) u64;
fn sat_subu8(a: u8, b: u8) u8;
fn sat_subz(a: size, b: size) size;
fn subi(a: int, b: int) (int, bool);
fn subi16(a: i16, b: i16) (i16, bool);
fn subi32(a: i32, b: i32) (i32, bool);
fn subi64(a: i64, b: i64) (i64, bool);
fn subi8(a: i8, b: i8) (i8, bool);
fn subu(a: uint, b: uint) (uint, bool);
fn subu16(a: u16, b: u16) (u16, bool);
fn subu32(a: u32, b: u32) (u32, bool);
fn subu64(a: u64, b: u64) (u64, bool);
fn subu8(a: u8, b: u8) (u8, bool);
fn subz(a: size, b: size) (size, bool);

Functions

fn addi[permalink] [source]

fn addi(a: int, b: int) (int, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addi16[permalink] [source]

fn addi16(a: i16, b: i16) (i16, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addi32[permalink] [source]

fn addi32(a: i32, b: i32) (i32, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addi64[permalink] [source]

fn addi64(a: i64, b: i64) (i64, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addi8[permalink] [source]

fn addi8(a: i8, b: i8) (i8, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addu[permalink] [source]

fn addu(a: uint, b: uint) (uint, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addu16[permalink] [source]

fn addu16(a: u16, b: u16) (u16, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addu32[permalink] [source]

fn addu32(a: u32, b: u32) (u32, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addu64[permalink] [source]

fn addu64(a: u64, b: u64) (u64, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addu8[permalink] [source]

fn addu8(a: u8, b: u8) (u8, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn addz[permalink] [source]

fn addz(a: size, b: size) (size, bool);

Adds 'a' and 'b', returning the result and whether overflow occurred.

fn muli[permalink] [source]

fn muli(a: int, b: int) (int, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn muli16[permalink] [source]

fn muli16(a: i16, b: i16) (i16, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn muli32[permalink] [source]

fn muli32(a: i32, b: i32) (i32, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn muli64[permalink] [source]

fn muli64(a: i64, b: i64) (i64, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn muli8[permalink] [source]

fn muli8(a: i8, b: i8) (i8, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn mulu[permalink] [source]

fn mulu(a: uint, b: uint) (uint, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn mulu16[permalink] [source]

fn mulu16(a: u16, b: u16) (u16, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn mulu32[permalink] [source]

fn mulu32(a: u32, b: u32) (u32, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn mulu64[permalink] [source]

fn mulu64(a: u64, b: u64) (u64, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn mulu8[permalink] [source]

fn mulu8(a: u8, b: u8) (u8, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn mulz[permalink] [source]

fn mulz(a: size, b: size) (size, bool);

Multiplies 'a' and 'b' returning the result and whether overflow occurred.

fn sat_addi[permalink] [source]

fn sat_addi(a: int, b: int) int;

Computes the saturating addition of 'a' and 'b'.

fn sat_addi16[permalink] [source]

fn sat_addi16(a: i16, b: i16) i16;

Computes the saturating addition of 'a' and 'b'.

fn sat_addi32[permalink] [source]

fn sat_addi32(a: i32, b: i32) i32;

Computes the saturating addition of 'a' and 'b'.

fn sat_addi64[permalink] [source]

fn sat_addi64(a: i64, b: i64) i64;

Computes the saturating addition of 'a' and 'b'.

fn sat_addi8[permalink] [source]

fn sat_addi8(a: i8, b: i8) i8;

Computes the saturating addition of 'a' and 'b'.

fn sat_addu[permalink] [source]

fn sat_addu(a: uint, b: uint) uint;

Computes the saturating addition of 'a' and 'b'.

fn sat_addu16[permalink] [source]

fn sat_addu16(a: u16, b: u16) u16;

Computes the saturating addition of 'a' and 'b'.

fn sat_addu32[permalink] [source]

fn sat_addu32(a: u32, b: u32) u32;

Computes the saturating addition of 'a' and 'b'.

fn sat_addu64[permalink] [source]

fn sat_addu64(a: u64, b: u64) u64;

Computes the saturating addition of 'a' and 'b'.

fn sat_addu8[permalink] [source]

fn sat_addu8(a: u8, b: u8) u8;

Computes the saturating addition of 'a' and 'b'.

fn sat_addz[permalink] [source]

fn sat_addz(a: size, b: size) size;

Computes the saturating addition of 'a' and 'b'.

fn sat_muli[permalink] [source]

fn sat_muli(a: int, b: int) int;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_muli16[permalink] [source]

fn sat_muli16(a: i16, b: i16) i16;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_muli32[permalink] [source]

fn sat_muli32(a: i32, b: i32) i32;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_muli64[permalink] [source]

fn sat_muli64(a: i64, b: i64) i64;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_muli8[permalink] [source]

fn sat_muli8(a: i8, b: i8) i8;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_mulu[permalink] [source]

fn sat_mulu(a: uint, b: uint) uint;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_mulu16[permalink] [source]

fn sat_mulu16(a: u16, b: u16) u16;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_mulu32[permalink] [source]

fn sat_mulu32(a: u32, b: u32) u32;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_mulu64[permalink] [source]

fn sat_mulu64(a: u64, b: u64) u64;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_mulu8[permalink] [source]

fn sat_mulu8(a: u8, b: u8) u8;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_mulz[permalink] [source]

fn sat_mulz(a: size, b: size) size;

Computes the saturating multiplication of 'a' and 'b'.

fn sat_subi[permalink] [source]

fn sat_subi(a: int, b: int) int;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subi16[permalink] [source]

fn sat_subi16(a: i16, b: i16) i16;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subi32[permalink] [source]

fn sat_subi32(a: i32, b: i32) i32;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subi64[permalink] [source]

fn sat_subi64(a: i64, b: i64) i64;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subi8[permalink] [source]

fn sat_subi8(a: i8, b: i8) i8;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subu[permalink] [source]

fn sat_subu(a: uint, b: uint) uint;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subu16[permalink] [source]

fn sat_subu16(a: u16, b: u16) u16;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subu32[permalink] [source]

fn sat_subu32(a: u32, b: u32) u32;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subu64[permalink] [source]

fn sat_subu64(a: u64, b: u64) u64;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subu8[permalink] [source]

fn sat_subu8(a: u8, b: u8) u8;

Computes the saturating subtraction of 'b' from 'a'.

fn sat_subz[permalink] [source]

fn sat_subz(a: size, b: size) size;

Computes the saturating subtraction of 'b' from 'a'.

fn subi[permalink] [source]

fn subi(a: int, b: int) (int, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subi16[permalink] [source]

fn subi16(a: i16, b: i16) (i16, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subi32[permalink] [source]

fn subi32(a: i32, b: i32) (i32, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subi64[permalink] [source]

fn subi64(a: i64, b: i64) (i64, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subi8[permalink] [source]

fn subi8(a: i8, b: i8) (i8, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subu[permalink] [source]

fn subu(a: uint, b: uint) (uint, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subu16[permalink] [source]

fn subu16(a: u16, b: u16) (u16, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subu32[permalink] [source]

fn subu32(a: u32, b: u32) (u32, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subu64[permalink] [source]

fn subu64(a: u64, b: u64) (u64, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subu8[permalink] [source]

fn subu8(a: u8, b: u8) (u8, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.

fn subz[permalink] [source]

fn subz(a: size, b: size) (size, bool);

Subtracts 'b' from 'a', returning the result and whether overflow occurred.