ops

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package ops contains generics for go's built-in operators. two-operator arithmetic:

+: Add
%: Mod
*: Mul
/: Div

two-operator comparison

==: Eq
 <: Less
<=: Leq
 >: Gt
>=: Geq

two-operator binary arithmetic:

 |: BinOr
 &: BinAnd
 ^: BinXor
>>: ShiftRight
<<: ShiftLeft

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[T Number | ~string](a, b T) T

Add is the + operator. It works on strings, too!

func BitAnd

func BitAnd[T constraints.Integer](a, b T) T

BitAnd is the & operator.

func BitInvert

func BitInvert[T constraints.Integer](a T) T

BinInvert is the bitwise negation operator, unary ^.

func BitOr

func BitOr[T constraints.Integer](a, b T) T

BitOr is the | operator.

func BitXor

func BitXor[T constraints.Integer](a, b T) T

BitXor is the ^ operator.

func Div

func Div[T Number](a, b T) T

Div is the * operator.

func Eq

func Eq[T comparable](a, b T) bool

Eq is the == operator.

func Geq

func Geq[T constraints.Ordered](a, b T) bool

Geq is the >= operator.

func Greater

func Greater[T constraints.Ordered](a, b T) bool

Greater is the > operator.

func Identity

func Identity[T any](a T) T

Identity returns T.

func Leq

func Leq[T constraints.Ordered](a, b T) bool

Leq is the < operator.

func Less

func Less[T constraints.Ordered](a, b T) bool

Less is the < operator.

func Mod

func Mod[T constraints.Integer](a, b T) T

Mod is the % operator.

func Mul

func Mul[T Number](a, b T) T

Mul is the * operator.

func Negate

Negate returns the negative of the integer.

func Neq

func Neq[T comparable](a, b T) bool

Neq is the != operator.

func ShiftLeft

func ShiftLeft[T constraints.Integer](a, b T) T

ShiftLeft is the << operator.

func ShiftRight

func ShiftRight[T constraints.Integer](a, b T) T

ShiftRight is the >> operator.

func Sub

func Sub[T Number](a, b T) T

Sub is the - operator.

Types

type Number

type Number interface {
	constraints.Float | constraints.Integer | constraints.Complex
}

Number is uint8..=64, int8..=64, float32..=64, complex64..=128

Jump to

Keyboard shortcuts

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