math

package
v0.0.63 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt8

func AbsInt8(n int8) int8

AbsInt8 gets absolute value of int8.

Example 1: AbsInt8(-5) -5 code value as below original code 1000,0101 inverse code 1111,1010 complement code 1111,1011 Negative numbers are represented by complement code in memory. shifted = n >> 7 = (1111,1011) >> 7 = 1111,1111 = -1(10-base) (负数右移,左补1)

1111,1011

n xor shifted = ----------- = 0000,0100 = 4(10-base)

1111,1111

(n ^ shifted) - shifted = 4 - (-1) = 5

Example 2: AbsInt8(5) 5 code value as below original code 0000,0101 Positive numbers are represented by original code in memory, and the XOR operation between positive numbers and 0 is equal to itself. shifted = n >> 7 = 0

0000,0101

n xor shifted = ----------- = 0000,0101 = 5(10-base)

0000,0000

(n ^ shifted) - shifted = 5 - 0 = 5

func AbsInt16

func AbsInt16(n int16) int16

AbsInt16 gets absolute value of int16.

func AbsInt32

func AbsInt32(n int32) int32

AbsInt32 gets absolute value of int32.

func AbsInt64

func AbsInt64(n int64) int64

AbsInt64 gets absolute value of int64.

func Max added in v0.0.62

func Max[T cmp.Ordered](x, y T) T

Max compare two values and return larger value. Deprecated: as of go 1.21, please use builtin func max.

func Min added in v0.0.62

func Min[T cmp.Ordered](x, y T) T

Min compare two values and return smaller value. Deprecated: as of go 1.21, please use builtin func min.

func RandAlphanumeric added in v0.0.52

func RandAlphanumeric(l int) string

RandAlphanumeric returns a truly random string of the specified length and the contents of which are composed of alphanumeric letters.

func RandBytes added in v0.0.52

func RandBytes(l uint32) []byte

RandBytes gets a truly random byte slice of the specified length with the value range in [0x00,0xff].

func RandInt

func RandInt() int

RandInt returns a non-negative truly random int number.

func RandIntRange

func RandIntRange(min, max int) int

RandIntRange returns a non-negative truly random int number in [min,max).

func RandIntn

func RandIntn(n int) int

RandIntn returns a non-negative truly random int number in [0,n).

func RandInts added in v0.0.52

func RandInts(l, max int) []int

RandInts returns a non-negative truly random int specified length slice with the value range in [0,max).

func RandLowerAlphanumeric added in v0.0.53

func RandLowerAlphanumeric(l int) string

RandLowerAlphanumeric returns a truly random string of the specified length and the contents of which are composed of lowercase letters and numbers.

func RandLowerStr

func RandLowerStr(l uint32) string

RandLowerStr returns a truly random lowercase string of a specified length.

func RandStr

func RandStr(l int) string

RandStr returns a truly random string of the specified length and the contents of which are composed of uppercase and lowercase letters.

func RandUpperStr

func RandUpperStr(l uint32) string

RandUpperStr returns a truly random uppercase string of a specified length.

Types

This section is empty.

Jump to

Keyboard shortcuts

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