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 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 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 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 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 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_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_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_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_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_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 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 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);

Functions

fn addi16[link]

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

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

fn addi32[link]

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

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

fn addi64[link]

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

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

fn addi8[link]

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

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

fn addu16[link]

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

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

fn addu32[link]

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

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

fn addu64[link]

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

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

fn addu8[link]

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

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

fn muli16[link]

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

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

fn muli32[link]

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

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

fn muli64[link]

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

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

fn muli8[link]

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

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

fn mulu16[link]

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

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

fn mulu32[link]

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

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

fn mulu64[link]

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

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

fn mulu8[link]

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

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

fn sat_addi16[link]

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

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

fn sat_addi32[link]

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

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

fn sat_addi64[link]

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

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

fn sat_addi8[link]

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

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

fn sat_addu16[link]

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

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

fn sat_addu32[link]

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

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

fn sat_addu64[link]

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

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

fn sat_addu8[link]

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

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

fn sat_muli16[link]

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

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

fn sat_muli32[link]

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

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

fn sat_muli64[link]

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

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

fn sat_muli8[link]

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

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

fn sat_mulu16[link]

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

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

fn sat_mulu32[link]

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

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

fn sat_mulu64[link]

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

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

fn sat_mulu8[link]

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

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

fn sat_subi16[link]

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

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

fn sat_subi32[link]

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

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

fn sat_subi64[link]

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

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

fn sat_subi8[link]

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

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

fn sat_subu16[link]

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

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

fn sat_subu32[link]

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

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

fn sat_subu64[link]

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

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

fn sat_subu8[link]

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

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

fn subi16[link]

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

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

fn subi32[link]

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

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

fn subi64[link]

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

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

fn subi8[link]

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

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

fn subu16[link]

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

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

fn subu32[link]

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

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

fn subu64[link]

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

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

fn subu8[link]

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

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