math

package
v0.37.0-dev Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0 Imports: 5 Imported by: 197

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOverflowInt32 = errors.New("int32 overflow")
View Source
var ErrOverflowInt8 = errors.New("int8 overflow")
View Source
var ErrOverflowUint8 = errors.New("uint8 overflow")

Functions

func MaxInt

func MaxInt(a, b int) int

func MaxInt64

func MaxInt64(a, b int64) int64

func MinInt

func MinInt(a, b int) int

func MinInt64

func MinInt64(a, b int64) int64

func SafeAddInt32 added in v0.34.0

func SafeAddInt32(a, b int32) (int32, error)

SafeAddInt32 adds two int32 integers.

func SafeConvertInt32 added in v0.34.0

func SafeConvertInt32(a int64) (int32, error)

SafeConvertInt32 takes a int and checks if it overflows.

func SafeConvertInt8 added in v0.34.0

func SafeConvertInt8(a int64) (int8, error)

SafeConvertInt8 takes an int64 and checks if it overflows.

func SafeConvertUint8 added in v0.34.0

func SafeConvertUint8(a int64) (uint8, error)

SafeConvertUint8 takes an int64 and checks if it overflows.

func SafeSubInt32 added in v0.34.0

func SafeSubInt32(a, b int32) (int32, error)

SafeSubInt32 subtracts two int32 integers.

Types

type Fraction

type Fraction struct {
	// The portion of the denominator in the faction, e.g. 2 in 2/3.
	Numerator uint64 `json:"numerator"`
	// The value by which the numerator is divided, e.g. 3 in 2/3.
	Denominator uint64 `json:"denominator"`
}

Fraction defined in terms of a numerator divided by a denominator in uint64 format. Fraction must be positive.

func ParseFraction added in v0.34.0

func ParseFraction(f string) (Fraction, error)

ParseFractions takes the string of a fraction as input i.e "2/3" and converts this to the equivalent fraction else returns an error. The format of the string must be one number followed by a slash (/) and then the other number.

func (Fraction) String

func (fr Fraction) String() string

Jump to

Keyboard shortcuts

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