branchless

package module
v0.0.0-...-19da385 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 0 Imported by: 2

README

Branchless

Branchless is a Go package that provides branchless operations on integers. It assumes int is 64-bit so will not work correctly on 32-bit architecture.

Functions

Min(x, y int) int

Returns the minimum of x and y.

Max(x, y int) int

Returns the maximum of x and y.

MaxZeroAnd(x int) int

Returns 0 if x is less than 0, otherwise x.

LessThan(x, y int) int

Returns 1 if x < y, otherwise 0.

GreaterThan(x, y int) int

Returns 1 if x > y, otherwise 0.

Equal(x, y int) int

Returns 1 if x == y, otherwise 0.

NotEqual(x, y int) int

Returns 1 if x != y, otherwise 0.

LessThanEqualTo(x, y int) int

Returns 1 if x <= y, otherwise 0.

GreaterThanEqualTo(x, y int) int

Returns 1 if x >= y, otherwise 0.

Abs(x int) int

Returns the absolute value of x.

Diff(x, y int) int

Returns the absolute difference between x and y.

Sign(x int) int

Returns -1 if x < 0, 0 if x == 0, and 1 if x > 0.

IsPositive(x int) int

Returns 1 if x > 0, otherwise 0.

IsNegative(x int) int

Returns 1 if x < 0, otherwise 0.

IsZero(x int) int

Returns 1 if x == 0, otherwise 0.

IsNotZero(x int) int

Returns 1 if x != 0, otherwise 0.

Clamp(x, min, max int) int

Clamps the value x between the minimum (min) and maximum (max) values.

IsPowerOfTwo(x int) int

Returns 1 if x is a power of 2 (or is zero), otherwise 0.

IsEven(x int) int

Returns 1 if x is even, otherwise 0.

IsOdd(x int) int

Returns 1 if x is odd, otherwise 0.

Negate(x int) int

Returns the negation of x.

IsDivisibleBy(x, y int) int

Returns 1 if x is divisible by y, otherwise 0.

Documentation

Overview

Package branchless provides branchless operations on integers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

Abs returns the absolute value of x.

func Clamp

func Clamp(x, min, max int) int

Clamp clamps the value x between the minimum (min) and maximum (max) values.

func Diff

func Diff(x, y int) int

Diff returns the absolute difference between x and y.

func Equal

func Equal(x, y int) int

Equal returns 1 if x == y, otherwise 0.

func GreaterThan

func GreaterThan(x, y int) int

GreaterThan returns 1 if x > y, otherwise 0.

func GreaterThanEqualTo

func GreaterThanEqualTo(x, y int) int

GreaterThanEqualTo returns 1 if x >= y, otherwise 0.

func IsDivisibleBy

func IsDivisibleBy(x, y int) int

IsDivisibleBy returns 1 if x is divisible by y, otherwise 0.

func IsEven

func IsEven(x int) int

IsEven returns 1 if x is even, otherwise 0.

func IsNegative

func IsNegative(x int) int

IsNegative returns 1 if x < 0, otherwise 0.

func IsNotZero

func IsNotZero(x int) int

IsNotZero returns 1 if x != 0, otherwise 0.

func IsOdd

func IsOdd(x int) int

IsOdd returns 1 if x is odd, otherwise 0.

func IsPositive

func IsPositive(x int) int

IsPositive returns 1 if x > 0, otherwise 0.

func IsPowerOfTwo

func IsPowerOfTwo(x int) int

IsPowerOfTwo returns 1 if x is a power of 2 (or is zero), otherwise 0.

func IsZero

func IsZero(x int) int

IsZero returns 1 if x == 0, otherwise 0.

func LessThan

func LessThan(x, y int) int

LessThan returns 1 if x < y, otherwise 0.

func LessThanEqualTo

func LessThanEqualTo(x, y int) int

LessThanEqualTo returns 1 if x <= y, otherwise 0.

func Max

func Max(x, y int) int

Max returns the maximum of x and y.

func MaxZeroAnd

func MaxZeroAnd(x int) int

MaxZeroAnd returns 0 if x is less than 0, otherwise x.

func Min

func Min(x, y int) int

Min returns the minimum of x and y.

func Negate

func Negate(x int) int

Negate returns the negation of x.

func NotEqual

func NotEqual(x, y int) int

NotEqual returns 1 if x != y, otherwise 0.

func Sign

func Sign(x int) int

Sign returns -1 if x < 0, 0 if x == 0, and 1 if x > 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL