mathext

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Int8    = new(I8)
	Int16   = new(I16)
	Int32   = new(I32)
	Int64   = new(I64)
	Int     = new(INT)
	UInt8   = new(U8)
	UInt16  = new(U16)
	UInt32  = new(U32)
	UInt64  = new(U64)
	UInt    = new(UINT)
	Float32 = new(F32)
	Float64 = new(F64)
)

Functions

func IsAlmostEqualFloat32

func IsAlmostEqualFloat32(a, b float32) bool

func IsAlmostEqualFloat64

func IsAlmostEqualFloat64(a, b float64) bool

Returns true if this number is at most kMaxUlps ULP's away from rhs. In particular, this function:

  • returns false if either number is (or both are) NAN.
  • treats really large numbers as almost equal to infinity.
  • thinks +0.0 and -0.0 are 0 DLP's apart.

func RandFloat

func RandFloat(min, max float64) float64

Random number in [min, max]

func RandInt

func RandInt(min, max int) int

Random integer in [min, max]

func RangePerm

func RangePerm(min, max int) []int

集合内随机取数, [min,max]

func RoundHalf

func RoundHalf(v float64) int

四舍五入

func SignAndMagnitudeToBiasedFloat32

func SignAndMagnitudeToBiasedFloat32(sam uint32) uint32

func SignAndMagnitudeToBiasedFloat64

func SignAndMagnitudeToBiasedFloat64(sam uint64) uint64

Converts an integer from the sign-and-magnitude representation to the biased representation. More precisely, let N be 2 to the power of (kBitCount - 1), an integer x is represented by the unsigned number x + N.

For instance,

-N + 1 (the most negative number representable using
       sign-and-magnitude) is represented by 1;
0      is represented by N; and
N - 1  (the biggest number representable using
       sign-and-magnitude) is represented by 2N - 1.

Read http://en.wikipedia.org/wiki/Signed_number_representations for more details on signed number representations.

Types

type F32

type F32 float32

func (F32) Abs

func (F32) Abs(x float32) float32

func (F32) Dim

func (a F32) Dim(x, y float32) float32

func (F32) Max

func (F32) Max(x, y float32) float32

func (F32) Min

func (F32) Min(x, y float32) float32

func (F32) SafeDiv

func (a F32) SafeDiv(x, y float32) float32

type F64

type F64 float64

func (F64) Abs

func (F64) Abs(x float64) float64

func (F64) Dim

func (a F64) Dim(x, y float64) float64

func (F64) Max

func (F64) Max(x, y float64) float64

func (F64) Min

func (F64) Min(x, y float64) float64

func (F64) SafeDiv

func (a F64) SafeDiv(x, y float64) float64

type I16

type I16 int16

func (I16) Abs

func (I16) Abs(x int16) int16

func (I16) Dim

func (a I16) Dim(x, y int16) int16

func (I16) Max

func (I16) Max(x, y int16) int16

func (I16) Min

func (I16) Min(x, y int16) int16

type I32

type I32 int32

func (I32) Abs

func (I32) Abs(x int32) int32

func (I32) Dim

func (a I32) Dim(x, y int32) int32

func (I32) Max

func (I32) Max(x, y int32) int32

func (I32) Min

func (I32) Min(x, y int32) int32

type I64

type I64 int64

func (I64) Abs

func (I64) Abs(x int64) int64

func (I64) Dim

func (a I64) Dim(x, y int64) int64

func (I64) Max

func (I64) Max(x, y int64) int64

func (I64) Min

func (I64) Min(x, y int64) int64

type I8

type I8 int8

func (I8) Abs

func (I8) Abs(x int8) int8

func (I8) Dim

func (a I8) Dim(x, y int8) int8

func (I8) Max

func (I8) Max(x, y int8) int8

func (I8) Min

func (I8) Min(x, y int8) int8

type INT

type INT int

func (INT) Abs

func (INT) Abs(x int) int

func (INT) Dim

func (a INT) Dim(x, y int) int

func (INT) Max

func (INT) Max(x, y int) int

func (INT) Min

func (INT) Min(x, y int) int

type LCRNG added in v1.0.2

type LCRNG struct {
	// contains filtered or unexported fields
}

线性同余数法 Linear congruential random number generator see https://en.wikipedia.org/wiki/Linear_congruential_generator

func (*LCRNG) Rand added in v1.0.2

func (g *LCRNG) Rand() uint32

func (*LCRNG) Seed added in v1.0.2

func (g *LCRNG) Seed(seed uint32)

type Point2 added in v1.0.2

type Point2 struct {
	X, Y int
}

Two dimensional point

var EmptyPoint Point2

func NewPoint2 added in v1.0.2

func NewPoint2(x, y int) *Point2

Allocates and returns a new 2D point

func (*Point2) Dist added in v1.0.2

func (a *Point2) Dist(b *Point2) float64

Calculates the distance between x and y

func (*Point2) Equal added in v1.0.2

func (a *Point2) Equal(b *Point2) bool

Returns whether two points are equal

type Rectangle added in v1.0.2

type Rectangle struct {
	X, Y          int // 原点
	Width, Height int // 宽度、高度
}
var (
	EmptyRect Rectangle
)

func NewRectangle added in v1.0.2

func NewRectangle(x, y, w, h int) *Rectangle

func RectIntersect added in v1.0.2

func RectIntersect(a *Rectangle, b *Rectangle) *Rectangle

Creates a rectangle that represents the intersetion between a and b

func RectUnion added in v1.0.2

func RectUnion(a *Rectangle, b *Rectangle) *Rectangle

Creates a rectangle that represents the union between a and b

func (*Rectangle) Contains added in v1.0.2

func (r *Rectangle) Contains(x, y int) bool

Determines if a point is contained within the rectangle

func (*Rectangle) ContainsPoint added in v1.0.2

func (r *Rectangle) ContainsPoint(pt Point2) bool

func (*Rectangle) ContainsRegion added in v1.0.2

func (r *Rectangle) ContainsRegion(rec *Rectangle) bool

func (*Rectangle) GetVertexes added in v1.0.2

func (r *Rectangle) GetVertexes() [4]Point2

func (*Rectangle) Inflate added in v1.0.2

func (r *Rectangle) Inflate(width, height int)

Inflates this rectangle

func (*Rectangle) IsIntersectsWith added in v1.0.2

func (r *Rectangle) IsIntersectsWith(rec *Rectangle) bool

Determines if this rectangle intersets with rect.

type U16

type U16 uint16

func (U16) Abs

func (U16) Abs(x uint16) uint16

func (U16) Dim

func (a U16) Dim(x, y uint16) uint16

func (U16) Max

func (U16) Max(x, y uint16) uint16

func (U16) Min

func (U16) Min(x, y uint16) uint16

type U32

type U32 uint32

func (U32) Abs

func (U32) Abs(x uint32) uint32

func (U32) Dim

func (a U32) Dim(x, y uint32) uint32

func (U32) Max

func (U32) Max(x, y uint32) uint32

func (U32) Min

func (U32) Min(x, y uint32) uint32

type U64

type U64 uint64

func (U64) Abs

func (U64) Abs(x uint64) uint64

func (U64) Dim

func (a U64) Dim(x, y uint64) uint64

func (U64) Max

func (U64) Max(x, y uint64) uint64

func (U64) Min

func (U64) Min(x, y uint64) uint64

type U8

type U8 uint8

func (U8) Abs

func (U8) Abs(x uint8) uint8

func (U8) Dim

func (a U8) Dim(x, y uint8) uint8

func (U8) Max

func (U8) Max(x, y uint8) uint8

func (U8) Min

func (U8) Min(x, y uint8) uint8

type UINT

type UINT uint

func (UINT) Abs

func (UINT) Abs(x uint) uint

func (UINT) Dim

func (a UINT) Dim(x, y uint) uint

func (UINT) Max

func (UINT) Max(x, y uint) uint

func (UINT) Min

func (UINT) Min(x, y uint) uint

type Vec2 added in v1.0.2

type Vec2 struct {
	X, Y int
}

Two dimensional vector.

func NewVec2ByPoint added in v1.0.2

func NewVec2ByPoint(a, b Point2) *Vec2

Allocates and returns a new 2D vector.

func (*Vec2) Add added in v1.0.2

func (a *Vec2) Add(b *Vec2) Vec2

func (*Vec2) Cross added in v1.0.2

func (a *Vec2) Cross(b *Vec2) int

Returns the cross product of x and y

func (*Vec2) Dot added in v1.0.2

func (a *Vec2) Dot(b *Vec2) int

Returns the dot product of x and y

func (*Vec2) Mul added in v1.0.2

func (a *Vec2) Mul(m float64) Vec2

func (*Vec2) Norm added in v1.0.2

func (a *Vec2) Norm() float64

Returns the length of x.

func (*Vec2) Normalize added in v1.0.2

func (a *Vec2) Normalize() Vec2

Normalize returns a unit point in the same direction as p.

func (*Vec2) Sub added in v1.0.2

func (a *Vec2) Sub(b *Vec2) Vec2

Jump to

Keyboard shortcuts

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