huge

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 2 Imported by: 0

README

Huge

Go doc

暂无介绍...

目录导航

列出了该 package 下所有的函数及类型定义,可通过目录导航进行快捷跳转 ❤️

展开 / 折叠目录导航

包级函数定义

函数名称 描述
NewFloat 创建一个 Float
NewFloatByString 通过字符串创建一个 Float
NewInt 创建一个 Int 对象,该对象的值为 x

类型定义

类型 名称 描述
STRUCT Float 暂无描述...
STRUCT Int 暂无描述...

详情信息

func NewFloat[T generic.Number](x T) *Float

创建一个 Float


func NewFloatByString(i string) *Float

通过字符串创建一个 Float

  • 如果字符串不是一个合法的数字,则返回 0

func NewInt[T generic.Basic](x T) *Int

创建一个 Int 对象,该对象的值为 x

示例代码:

该案例展示了 NewInt 对各种基本类型的支持及用法


func ExampleNewInt() {
	fmt.Println(huge.NewInt("12345678900000000"))
	fmt.Println(huge.NewInt(1234567890))
	fmt.Println(huge.NewInt(true))
	fmt.Println(huge.NewInt(123.123))
	fmt.Println(huge.NewInt(byte(1)))
}

查看 / 收起单元测试

func TestNewInt(t *testing.T) {
	var cases = []struct {
		name string
		nil  bool
		in   int64
		mul  int64
		want string
	}{{name: "TestNewIntNegative", in: -1, want: "-1"}, {name: "TestNewIntZero", in: 0, want: "0"}, {name: "TestNewIntPositive", in: 1, want: "1"}, {name: "TestNewIntMax", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestNewIntMin", in: -9223372036854775808, want: "-9223372036854775808"}, {name: "TestNewIntMulNegative", in: -9223372036854775808, mul: 10000000, want: "-92233720368547758080000000"}, {name: "TestNewIntMulPositive", in: 9223372036854775807, mul: 10000000, want: "92233720368547758070000000"}, {name: "TestNewIntNil", nil: true, want: "0"}, {name: "TestNewIntNilMul", nil: true, mul: 10000000, want: "0"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var got *huge.Int
			switch {
			case c.nil:
				if c.mul > 0 {
					got = huge.NewInt(0).MulInt64(c.mul)
				}
			case c.mul == 0:
				got = huge.NewInt(c.in)
			default:
				got = huge.NewInt(c.in).MulInt64(c.mul)
			}
			if s := got.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, got.String())
			} else {
				t.Log(s)
			}
		})
	}
	t.Run("TestNewIntFromString", func(t *testing.T) {
		if got := huge.NewInt("1234567890123456789012345678901234567890"); got.String() != "1234567890123456789012345678901234567890" {
			t.Fatalf("want: %s, got: %s", "1234567890123456789012345678901234567890", got.String())
		}
	})
	t.Run("TestNewIntFromInt", func(t *testing.T) {
		if got := huge.NewInt(1234567890); got.String() != "1234567890" {
			t.Fatalf("want: %s, got: %s", "1234567890", got.String())
		}
	})
	t.Run("TestNewIntFromBool", func(t *testing.T) {
		if got := huge.NewInt(true); got.String() != "1" {
			t.Fatalf("want: %s, got: %s", "1", got.String())
		}
	})
	t.Run("TestNewIntFromFloat", func(t *testing.T) {
		if got := huge.NewInt(1234567890.1234567890); got.String() != "1234567890" {
			t.Fatalf("want: %s, got: %s", "1234567890", got.String())
		}
	})
}


Float STRUCT
type Float big.Float

func (*Float) Copy() *Float

func (*Float) Set(i *Float) *Float

func (*Float) IsZero() bool

func (*Float) ToBigFloat() *big.Float

func (*Float) Cmp(i *Float) int

比较,当 slf > i 时返回 1,当 slf < i 时返回 -1,当 slf == i 时返回 0


func (*Float) GreaterThan(i *Float) bool

大于


func (*Float) GreaterThanOrEqualTo(i *Float) bool

大于或等于


func (*Float) LessThan(i *Float) bool

小于


func (*Float) LessThanOrEqualTo(i *Float) bool

小于或等于


func (*Float) EqualTo(i *Float) bool

等于


func (*Float) Float64() float64

func (*Float) String() string

func (*Float) Add(i *Float) *Float

func (*Float) Sub(i *Float) *Float

func (*Float) Mul(i *Float) *Float

func (*Float) Div(i *Float) *Float

func (*Float) Sqrt() *Float

平方根


func (*Float) Abs() *Float

返回数字的绝对值


func (*Float) Sign() int

返回数字的符号

  • 1:正数
  • 0:零
  • -1:负数

func (*Float) IsPositive() bool

是否为正数


func (*Float) IsNegative() bool

是否为负数


Int STRUCT
type Int big.Int

func (*Int) Copy() *Int

拷贝当前 Int 对象

示例代码:


func ExampleInt_Copy() {
	var a = huge.NewInt(1234567890)
	var b = a.Copy().SetInt64(9876543210)
	fmt.Println(a)
	fmt.Println(b)
}

查看 / 收起单元测试

func TestInt_Copy(t *testing.T) {
	var cases = []struct {
		name string
		in   int64
		want string
	}{{name: "TestIntCopyNegative", in: -1, want: "-1"}, {name: "TestIntCopyZero", in: 0, want: "0"}, {name: "TestIntCopyPositive", in: 1, want: "1"}, {name: "TestIntCopyMax", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestIntCopyMin", in: -9223372036854775808, want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in = huge.NewInt(c.in)
			var got = in.Copy()
			if in.Int64() != c.in {
				t.Fatalf("want: %d, got: %d", c.in, in.Int64())
			}
			if s := got.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, got.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) Set(i *Int) *Int

设置当前 Int 对象的值为 i

示例代码:


func ExampleInt_Set() {
	var a = huge.NewInt(1234567890)
	var b = huge.NewInt(9876543210)
	fmt.Println(a)
	a.Set(b)
	fmt.Println(a)
}

查看 / 收起单元测试

func TestInt_Set(t *testing.T) {
	var cases = []struct {
		name string
		in   int64
		want string
	}{{name: "TestIntSetNegative", in: -1, want: "-1"}, {name: "TestIntSetZero", in: 0, want: "0"}, {name: "TestIntSetPositive", in: 1, want: "1"}, {name: "TestIntSetMax", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestIntSetMin", in: -9223372036854775808, want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.Set(huge.NewInt(c.in))
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetString(i string) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetString(t *testing.T) {
	var cases = []struct {
		name string
		in   string
		want string
	}{{name: "TestIntSetStringNegative", in: "-1", want: "-1"}, {name: "TestIntSetStringZero", in: "0", want: "0"}, {name: "TestIntSetStringPositive", in: "1", want: "1"}, {name: "TestIntSetStringMax", in: "9223372036854775807", want: "9223372036854775807"}, {name: "TestIntSetStringMin", in: "-9223372036854775808", want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetString(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetInt(i int) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetInt(t *testing.T) {
	var cases = []struct {
		name string
		in   int64
		want string
	}{{name: "TestIntSetIntNegative", in: -1, want: "-1"}, {name: "TestIntSetIntZero", in: 0, want: "0"}, {name: "TestIntSetIntPositive", in: 1, want: "1"}, {name: "TestIntSetIntMax", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestIntSetIntMin", in: -9223372036854775808, want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetInt64(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetInt8(i int8) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetInt8(t *testing.T) {
	var cases = []struct {
		name string
		in   int8
		want string
	}{{name: "TestIntSetInt8Negative", in: -1, want: "-1"}, {name: "TestIntSetInt8Zero", in: 0, want: "0"}, {name: "TestIntSetInt8Positive", in: 1, want: "1"}, {name: "TestIntSetInt8Max", in: 127, want: "127"}, {name: "TestIntSetInt8Min", in: -128, want: "-128"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetInt8(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetInt16(i int16) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetInt16(t *testing.T) {
	var cases = []struct {
		name string
		in   int16
		want string
	}{{name: "TestIntSetInt16Negative", in: -1, want: "-1"}, {name: "TestIntSetInt16Zero", in: 0, want: "0"}, {name: "TestIntSetInt16Positive", in: 1, want: "1"}, {name: "TestIntSetInt16Max", in: 32767, want: "32767"}, {name: "TestIntSetInt16Min", in: -32768, want: "-32768"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetInt16(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetInt32(i int32) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetInt32(t *testing.T) {
	var cases = []struct {
		name string
		in   int32
		want string
	}{{name: "TestIntSetInt32Negative", in: -1, want: "-1"}, {name: "TestIntSetInt32Zero", in: 0, want: "0"}, {name: "TestIntSetInt32Positive", in: 1, want: "1"}, {name: "TestIntSetInt32Max", in: 2147483647, want: "2147483647"}, {name: "TestIntSetInt32Min", in: -2147483648, want: "-2147483648"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetInt32(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetInt64(i int64) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetInt64(t *testing.T) {
	var cases = []struct {
		name string
		in   int64
		want string
	}{{name: "TestIntSetInt64Negative", in: -1, want: "-1"}, {name: "TestIntSetInt64Zero", in: 0, want: "0"}, {name: "TestIntSetInt64Positive", in: 1, want: "1"}, {name: "TestIntSetInt64Max", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestIntSetInt64Min", in: -9223372036854775808, want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetInt64(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetUint(i uint) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetUint(t *testing.T) {
	var cases = []struct {
		name string
		in   uint64
		want string
	}{{name: "TestIntSetUintNegative", in: 0, want: "0"}, {name: "TestIntSetUintZero", in: 0, want: "0"}, {name: "TestIntSetUintPositive", in: 1, want: "1"}, {name: "TestIntSetUintMax", in: 18446744073709551615, want: "18446744073709551615"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetUint64(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetUint8(i uint8) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetUint8(t *testing.T) {
	var cases = []struct {
		name string
		in   uint8
		want string
	}{{name: "TestIntSetUint8Negative", in: 0, want: "0"}, {name: "TestIntSetUint8Zero", in: 0, want: "0"}, {name: "TestIntSetUint8Positive", in: 1, want: "1"}, {name: "TestIntSetUint8Max", in: 255, want: "255"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetUint8(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetUint16(i uint16) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetUint16(t *testing.T) {
	var cases = []struct {
		name string
		in   uint16
		want string
	}{{name: "TestIntSetUint16Negative", in: 0, want: "0"}, {name: "TestIntSetUint16Zero", in: 0, want: "0"}, {name: "TestIntSetUint16Positive", in: 1, want: "1"}, {name: "TestIntSetUint16Max", in: 65535, want: "65535"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetUint16(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetUint32(i uint32) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetUint32(t *testing.T) {
	var cases = []struct {
		name string
		in   uint32
		want string
	}{{name: "TestIntSetUint32Negative", in: 0, want: "0"}, {name: "TestIntSetUint32Zero", in: 0, want: "0"}, {name: "TestIntSetUint32Positive", in: 1, want: "1"}, {name: "TestIntSetUint32Max", in: 4294967295, want: "4294967295"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetUint32(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetUint64(i uint64) *Int

设置当前 Int 对象的值为 i

查看 / 收起单元测试

func TestInt_SetUint64(t *testing.T) {
	var cases = []struct {
		name string
		in   uint64
		want string
	}{{name: "TestIntSetUint64Negative", in: 0, want: "0"}, {name: "TestIntSetUint64Zero", in: 0, want: "0"}, {name: "TestIntSetUint64Positive", in: 1, want: "1"}, {name: "TestIntSetUint64Max", in: 18446744073709551615, want: "18446744073709551615"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetUint64(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetFloat32(i float32) *Int

设置当前 Int 对象的值为 i 向下取整后的值

查看 / 收起单元测试

func TestInt_SetFloat32(t *testing.T) {
	var cases = []struct {
		name string
		in   float32
		want string
	}{{name: "TestIntSetFloat32Negative", in: -1.1, want: "-1"}, {name: "TestIntSetFloat32Zero", in: 0, want: "0"}, {name: "TestIntSetFloat32Positive", in: 1.1, want: "1"}, {name: "TestIntSetFloat32Max", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestIntSetFloat32Min", in: -9223372036854775808, want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetFloat32(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetFloat64(i float64) *Int

设置当前 Int 对象的值为 i 向下取整后的值

查看 / 收起单元测试

func TestInt_SetFloat64(t *testing.T) {
	var cases = []struct {
		name string
		in   float64
		want string
	}{{name: "TestIntSetFloat64Negative", in: -1.1, want: "-1"}, {name: "TestIntSetFloat64Zero", in: 0, want: "0"}, {name: "TestIntSetFloat64Positive", in: 1.1, want: "1"}, {name: "TestIntSetFloat64Max", in: 9223372036854775807, want: "9223372036854775807"}, {name: "TestIntSetFloat64Min", in: -9223372036854775808, want: "-9223372036854775808"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetFloat64(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) SetBool(i bool) *Int

设置当前 Int 对象的值为 i,当 i 为 true 时,值为 1,当 i 为 false 时,值为 0

查看 / 收起单元测试

func TestInt_SetBool(t *testing.T) {
	var cases = []struct {
		name string
		in   bool
		want string
	}{{name: "TestIntSetBoolFalse", in: false, want: "0"}, {name: "TestIntSetBoolTrue", in: true, want: "1"}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var in *huge.Int
			in = in.SetBool(c.in)
			if s := in.String(); s != c.want {
				t.Fatalf("want: %s, got: %s", c.want, in.String())
			} else {
				t.Log(s)
			}
		})
	}
}


func (*Int) IsZero() bool

判断当前 Int 对象的值是否为 0

查看 / 收起单元测试

func TestInt_IsZero(t *testing.T) {
	var cases = []struct {
		name string
		in   int64
		want bool
	}{{name: "TestIntIsZeroNegative", in: -1, want: false}, {name: "TestIntIsZeroZero", in: 0, want: true}, {name: "TestIntIsZeroPositive", in: 1, want: false}, {name: "TestIntIsZeroMax", in: 9223372036854775807, want: false}, {name: "TestIntIsZeroMin", in: -9223372036854775808, want: false}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			if got := huge.NewInt(c.in).IsZero(); got != c.want {
				t.Fatalf("want: %t, got: %t", c.want, got)
			}
		})
	}
}


func (*Int) ToBigint() *big.Int

转换为 *big.Int

查看 / 收起单元测试

func TestInt_ToBigint(t *testing.T) {
	var cases = []struct {
		name string
		in   int64
		want *big.Int
	}{{name: "TestIntToBigintNegative", in: -1, want: big.NewInt(-1)}, {name: "TestIntToBigintZero", in: 0, want: big.NewInt(0)}, {name: "TestIntToBigintPositive", in: 1, want: big.NewInt(1)}, {name: "TestIntToBigintMax", in: 9223372036854775807, want: big.NewInt(9223372036854775807)}, {name: "TestIntToBigintMin", in: -9223372036854775808, want: big.NewInt(-9223372036854775808)}}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			if got := huge.NewInt(c.in).ToBigint(); got.Cmp(c.want) != 0 {
				t.Fatalf("want: %s, got: %s", c.want.String(), got.String())
			}
		})
	}
}


func (*Int) Cmp(i *Int) int

比较,当 slf > i 时返回 1,当 slf < i 时返回 -1,当 slf == i 时返回 0


func (*Int) GreaterThan(i *Int) bool

检查 slf 是否大于 i


func (*Int) GreaterThanOrEqualTo(i *Int) bool

检查 slf 是否大于或等于 i


func (*Int) LessThan(i *Int) bool

检查 slf 是否小于 i


func (*Int) LessThanOrEqualTo(i *Int) bool

检查 slf 是否小于或等于 i


func (*Int) EqualTo(i *Int) bool

检查 slf 是否等于 i


func (*Int) Int64() int64

转换为 int64 类型进行返回


func (*Int) String() string

转换为 string 类型进行返回


func (*Int) Add(i *Int) *Int

使用 i 对 slf 进行加法运算,slf 的值会变为运算后的值。返回 slf


func (*Int) AddInt(i int) *Int

func (*Int) AddInt8(i int8) *Int

func (*Int) AddInt16(i int16) *Int

func (*Int) AddInt32(i int32) *Int

func (*Int) AddInt64(i int64) *Int

func (*Int) AddUint(i uint) *Int

func (*Int) AddUint8(i uint8) *Int

func (*Int) AddUint16(i uint16) *Int

func (*Int) AddUint32(i uint32) *Int

func (*Int) AddUint64(i uint64) *Int

func (*Int) Mul(i *Int) *Int

func (*Int) MulInt(i int) *Int

func (*Int) MulInt8(i int8) *Int

func (*Int) MulInt16(i int16) *Int

func (*Int) MulInt32(i int32) *Int

func (*Int) MulInt64(i int64) *Int

func (*Int) MulUint(i uint) *Int

func (*Int) MulUint8(i uint8) *Int

func (*Int) MulUint16(i uint16) *Int

func (*Int) MulUint32(i uint32) *Int

func (*Int) MulUint64(i uint64) *Int

func (*Int) Sub(i *Int) *Int

func (*Int) SubInt(i int) *Int

func (*Int) SubInt8(i int8) *Int

func (*Int) SubInt16(i int16) *Int

func (*Int) SubInt32(i int32) *Int

func (*Int) SubInt64(i int64) *Int

func (*Int) SubUint(i uint) *Int

func (*Int) SubUint8(i uint8) *Int

func (*Int) SubUint16(i uint16) *Int

func (*Int) SubUint32(i uint32) *Int

func (*Int) SubUint64(i uint64) *Int

func (*Int) Div(i *Int) *Int

func (*Int) DivInt(i int) *Int

func (*Int) DivInt8(i int8) *Int

func (*Int) DivInt16(i int16) *Int

func (*Int) DivInt32(i int32) *Int

func (*Int) DivInt64(i int64) *Int

func (*Int) DivUint(i uint) *Int

func (*Int) DivUint8(i uint8) *Int

func (*Int) DivUint16(i uint16) *Int

func (*Int) DivUint32(i uint32) *Int

func (*Int) DivUint64(i uint64) *Int

func (*Int) Mod(i *Int) *Int

func (*Int) ModInt(i int) *Int

func (*Int) ModInt8(i int8) *Int

func (*Int) ModInt16(i int16) *Int

func (*Int) ModInt32(i int32) *Int

func (*Int) ModInt64(i int64) *Int

func (*Int) ModUint(i uint) *Int

func (*Int) ModUint8(i uint8) *Int

func (*Int) ModUint16(i uint16) *Int

func (*Int) ModUint32(i uint32) *Int

func (*Int) ModUint64(i uint64) *Int

func (*Int) Pow(i *Int) *Int

func (*Int) PowInt(i int) *Int

func (*Int) PowInt8(i int8) *Int

func (*Int) PowInt16(i int16) *Int

func (*Int) PowInt32(i int32) *Int

func (*Int) PowInt64(i int64) *Int

func (*Int) PowUint(i uint) *Int

func (*Int) PowUint8(i uint8) *Int

func (*Int) PowUint16(i uint16) *Int

func (*Int) PowUint32(i uint32) *Int

func (*Int) PowUint64(i uint64) *Int

func (*Int) Lsh(i int) *Int

左移


func (*Int) Rsh(i int) *Int

右移


func (*Int) And(i *Int) *Int


func (*Int) AndNot(i *Int) *Int

与非


func (*Int) Or(i *Int) *Int


func (*Int) Xor(i *Int) *Int

异或


func (*Int) Not() *Int


func (*Int) Sqrt() *Int

平方根


func (*Int) GCD(i *Int) *Int

最大公约数


func (*Int) LCM(i *Int) *Int

最小公倍数


func (*Int) ModInverse(i *Int) *Int

模反元素


func (*Int) ModSqrt(i *Int) *Int

模平方根


func (*Int) BitLen() int

二进制长度


func (*Int) Bit(i int) uint

二进制位


func (*Int) SetBit(i int, v uint) *Int

设置二进制位


func (*Int) Neg() *Int

返回数字的相反数


func (*Int) Abs() *Int

返回数字的绝对值


func (*Int) Sign() int

返回数字的符号

  • 1:正数
  • 0:零
  • -1:负数

func (*Int) IsPositive() bool

是否为正数


func (*Int) IsNegative() bool

是否为负数


func (*Int) IsEven() bool

是否为偶数


func (*Int) IsOdd() bool

是否为奇数


func (*Int) ProportionalCalc(proportional *Int, formula func (v *Int) *Int) *Int

比例计算,该函数会再 formula 返回值的基础上除以 proportional

  • formula 为计算公式,该公式的参数为调用该函数的 Int 的拷贝

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	FloatNegativeOne = NewFloat(-1.0)    // 默认初始化的-1值Float,应当将其当作常量使用
	FloatZero        = NewFloat(0.0)     // 默认初始化的0值Float,应当将其当作常量使用
	FloatOne         = NewFloat(1.0)     // 默认初始化的1值Float,应当将其当作常量使用
	FloatTen         = NewFloat(10.0)    // 默认初始化的10值Float,应当将其当作常量使用
	FloatHundred     = NewFloat(100.0)   // 默认初始化的100值Float,应当将其当作常量使用
	FloatThousand    = NewFloat(1000.0)  // 默认初始化的1000值Float,应当将其当作常量使用
	FloatTenThousand = NewFloat(10000.0) // 默认初始化的10000值Float,应当将其当作常量使用
)
View Source
var (
	IntNegativeOne = NewInt(-1)    // 默认初始化的-1值Int,应当将其当作常量使用
	IntZero        = NewInt(0)     // 默认初始化的0值Int,应当将其当作常量使用
	IntOne         = NewInt(1)     // 默认初始化的1值Int,应当将其当作常量使用
	IntTen         = NewInt(10)    // 默认初始化的10值Int,应当将其当作常量使用
	IntHundred     = NewInt(100)   // 默认初始化的100值Int,应当将其当作常量使用
	IntThousand    = NewInt(1000)  // 默认初始化的1000值Int,应当将其当作常量使用
	IntTenThousand = NewInt(10000) // 默认初始化的10000值Int,应当将其当作常量使用
)

Functions

This section is empty.

Types

type Float added in v0.4.1

type Float big.Float

func NewFloat added in v0.4.1

func NewFloat[T generic.Number](x T) *Float

NewFloat 创建一个 Float

func NewFloatByString added in v0.4.1

func NewFloatByString(i string) *Float

NewFloatByString 通过字符串创建一个 Float

  • 如果字符串不是一个合法的数字,则返回 0

func (*Float) Abs added in v0.4.1

func (slf *Float) Abs() *Float

Abs 返回数字的绝对值

func (*Float) Add added in v0.4.1

func (slf *Float) Add(i *Float) *Float

func (*Float) Cmp added in v0.4.1

func (slf *Float) Cmp(i *Float) int

Cmp 比较,当 slf > i 时返回 1,当 slf < i 时返回 -1,当 slf == i 时返回 0

func (*Float) Copy added in v0.4.1

func (slf *Float) Copy() *Float

func (*Float) Div added in v0.4.1

func (slf *Float) Div(i *Float) *Float

func (*Float) EqualTo added in v0.4.1

func (slf *Float) EqualTo(i *Float) bool

EqualTo 等于

func (*Float) Float64 added in v0.4.1

func (slf *Float) Float64() float64

func (*Float) GreaterThan added in v0.4.1

func (slf *Float) GreaterThan(i *Float) bool

GreaterThan 大于

func (*Float) GreaterThanOrEqualTo added in v0.4.1

func (slf *Float) GreaterThanOrEqualTo(i *Float) bool

GreaterThanOrEqualTo 大于或等于

func (*Float) IsNegative added in v0.4.1

func (slf *Float) IsNegative() bool

IsNegative 是否为负数

func (*Float) IsPositive added in v0.4.1

func (slf *Float) IsPositive() bool

IsPositive 是否为正数

func (*Float) IsZero added in v0.4.1

func (slf *Float) IsZero() bool

func (*Float) LessThan added in v0.4.1

func (slf *Float) LessThan(i *Float) bool

LessThan 小于

func (*Float) LessThanOrEqualTo added in v0.4.1

func (slf *Float) LessThanOrEqualTo(i *Float) bool

LessThanOrEqualTo 小于或等于

func (*Float) Mul added in v0.4.1

func (slf *Float) Mul(i *Float) *Float

func (*Float) Set added in v0.4.1

func (slf *Float) Set(i *Float) *Float

func (*Float) Sign added in v0.4.1

func (slf *Float) Sign() int

Sign 返回数字的符号

  • 1:正数
  • 0:零
  • -1:负数

func (*Float) Sqrt added in v0.4.1

func (slf *Float) Sqrt() *Float

Sqrt 平方根

func (*Float) String added in v0.4.1

func (slf *Float) String() string

func (*Float) Sub added in v0.4.1

func (slf *Float) Sub(i *Float) *Float

func (*Float) ToBigFloat added in v0.4.1

func (slf *Float) ToBigFloat() *big.Float

type Int

type Int big.Int

func NewInt

func NewInt[T generic.Basic](x T) *Int

NewInt 创建一个 Int 对象,该对象的值为 x

Example

该案例展示了 NewInt 对各种基本类型的支持及用法

package main

import (
	"fmt"
	"github.com/kercylan98/minotaur/utils/huge"
)

func main() {
	fmt.Println(huge.NewInt("12345678900000000"))
	fmt.Println(huge.NewInt(1234567890))
	fmt.Println(huge.NewInt(true))
	fmt.Println(huge.NewInt(123.123))
	fmt.Println(huge.NewInt(byte(1)))
}
Output:

12345678900000000
1234567890
1
123
1

func (*Int) Abs added in v0.3.4

func (slf *Int) Abs() *Int

Abs 返回数字的绝对值

func (*Int) Add

func (slf *Int) Add(i *Int) *Int

Add 使用 i 对 slf 进行加法运算,slf 的值会变为运算后的值。返回 slf

func (*Int) AddInt

func (slf *Int) AddInt(i int) *Int

func (*Int) AddInt16

func (slf *Int) AddInt16(i int16) *Int

func (*Int) AddInt32

func (slf *Int) AddInt32(i int32) *Int

func (*Int) AddInt64

func (slf *Int) AddInt64(i int64) *Int

func (*Int) AddInt8

func (slf *Int) AddInt8(i int8) *Int

func (*Int) AddUint

func (slf *Int) AddUint(i uint) *Int

func (*Int) AddUint16

func (slf *Int) AddUint16(i uint16) *Int

func (*Int) AddUint32

func (slf *Int) AddUint32(i uint32) *Int

func (*Int) AddUint64

func (slf *Int) AddUint64(i uint64) *Int

func (*Int) AddUint8

func (slf *Int) AddUint8(i uint8) *Int

func (*Int) And added in v0.3.4

func (slf *Int) And(i *Int) *Int

And 与

func (*Int) AndNot added in v0.3.4

func (slf *Int) AndNot(i *Int) *Int

AndNot 与非

func (*Int) Bit added in v0.3.4

func (slf *Int) Bit(i int) uint

Bit 二进制位

func (*Int) BitLen added in v0.3.4

func (slf *Int) BitLen() int

BitLen 二进制长度

func (*Int) Cmp

func (slf *Int) Cmp(i *Int) int

Cmp 比较,当 slf > i 时返回 1,当 slf < i 时返回 -1,当 slf == i 时返回 0

func (*Int) Copy

func (slf *Int) Copy() *Int

Copy 拷贝当前 Int 对象

Example
package main

import (
	"fmt"
	"github.com/kercylan98/minotaur/utils/huge"
)

func main() {
	var a = huge.NewInt(1234567890)
	var b = a.Copy().SetInt64(9876543210)
	fmt.Println(a)
	fmt.Println(b)
}
Output:

1234567890
9876543210

func (*Int) Div added in v0.3.4

func (slf *Int) Div(i *Int) *Int

func (*Int) DivInt added in v0.3.4

func (slf *Int) DivInt(i int) *Int

func (*Int) DivInt16 added in v0.3.4

func (slf *Int) DivInt16(i int16) *Int

func (*Int) DivInt32 added in v0.3.4

func (slf *Int) DivInt32(i int32) *Int

func (*Int) DivInt64 added in v0.3.4

func (slf *Int) DivInt64(i int64) *Int

func (*Int) DivInt8 added in v0.3.4

func (slf *Int) DivInt8(i int8) *Int

func (*Int) DivUint added in v0.3.4

func (slf *Int) DivUint(i uint) *Int

func (*Int) DivUint16 added in v0.3.4

func (slf *Int) DivUint16(i uint16) *Int

func (*Int) DivUint32 added in v0.3.4

func (slf *Int) DivUint32(i uint32) *Int

func (*Int) DivUint64 added in v0.3.4

func (slf *Int) DivUint64(i uint64) *Int

func (*Int) DivUint8 added in v0.3.4

func (slf *Int) DivUint8(i uint8) *Int

func (*Int) EqualTo

func (slf *Int) EqualTo(i *Int) bool

EqualTo 检查 slf 是否等于 i

func (*Int) GCD added in v0.3.4

func (slf *Int) GCD(i *Int) *Int

GCD 最大公约数

func (*Int) GreaterThan

func (slf *Int) GreaterThan(i *Int) bool

GreaterThan 检查 slf 是否大于 i

func (*Int) GreaterThanOrEqualTo

func (slf *Int) GreaterThanOrEqualTo(i *Int) bool

GreaterThanOrEqualTo 检查 slf 是否大于或等于 i

func (*Int) Int64

func (slf *Int) Int64() int64

Int64 转换为 int64 类型进行返回

func (*Int) IsEven added in v0.3.4

func (slf *Int) IsEven() bool

IsEven 是否为偶数

func (*Int) IsNegative added in v0.3.4

func (slf *Int) IsNegative() bool

IsNegative 是否为负数

func (*Int) IsOdd added in v0.3.4

func (slf *Int) IsOdd() bool

IsOdd 是否为奇数

func (*Int) IsPositive added in v0.3.4

func (slf *Int) IsPositive() bool

IsPositive 是否为正数

func (*Int) IsZero

func (slf *Int) IsZero() bool

IsZero 判断当前 Int 对象的值是否为 0

func (*Int) LCM added in v0.3.4

func (slf *Int) LCM(i *Int) *Int

LCM 最小公倍数

func (*Int) LessThan

func (slf *Int) LessThan(i *Int) bool

LessThan 检查 slf 是否小于 i

func (*Int) LessThanOrEqualTo

func (slf *Int) LessThanOrEqualTo(i *Int) bool

LessThanOrEqualTo 检查 slf 是否小于或等于 i

func (*Int) Lsh added in v0.3.4

func (slf *Int) Lsh(i int) *Int

Lsh 左移

func (*Int) Mod added in v0.3.4

func (slf *Int) Mod(i *Int) *Int

func (*Int) ModInt added in v0.3.4

func (slf *Int) ModInt(i int) *Int

func (*Int) ModInt16 added in v0.3.4

func (slf *Int) ModInt16(i int16) *Int

func (*Int) ModInt32 added in v0.3.4

func (slf *Int) ModInt32(i int32) *Int

func (*Int) ModInt64 added in v0.3.4

func (slf *Int) ModInt64(i int64) *Int

func (*Int) ModInt8 added in v0.3.4

func (slf *Int) ModInt8(i int8) *Int

func (*Int) ModInverse added in v0.3.4

func (slf *Int) ModInverse(i *Int) *Int

ModInverse 模反元素

func (*Int) ModSqrt added in v0.3.4

func (slf *Int) ModSqrt(i *Int) *Int

ModSqrt 模平方根

func (*Int) ModUint added in v0.3.4

func (slf *Int) ModUint(i uint) *Int

func (*Int) ModUint16 added in v0.3.4

func (slf *Int) ModUint16(i uint16) *Int

func (*Int) ModUint32 added in v0.3.4

func (slf *Int) ModUint32(i uint32) *Int

func (*Int) ModUint64 added in v0.3.4

func (slf *Int) ModUint64(i uint64) *Int

func (*Int) ModUint8 added in v0.3.4

func (slf *Int) ModUint8(i uint8) *Int

func (*Int) Mul

func (slf *Int) Mul(i *Int) *Int

func (*Int) MulInt

func (slf *Int) MulInt(i int) *Int

func (*Int) MulInt16

func (slf *Int) MulInt16(i int16) *Int

func (*Int) MulInt32

func (slf *Int) MulInt32(i int32) *Int

func (*Int) MulInt64

func (slf *Int) MulInt64(i int64) *Int

func (*Int) MulInt8

func (slf *Int) MulInt8(i int8) *Int

func (*Int) MulUint

func (slf *Int) MulUint(i uint) *Int

func (*Int) MulUint16

func (slf *Int) MulUint16(i uint16) *Int

func (*Int) MulUint32

func (slf *Int) MulUint32(i uint32) *Int

func (*Int) MulUint64

func (slf *Int) MulUint64(i uint64) *Int

func (*Int) MulUint8

func (slf *Int) MulUint8(i uint8) *Int

func (*Int) Neg added in v0.3.4

func (slf *Int) Neg() *Int

Neg 返回数字的相反数

func (*Int) Not added in v0.3.4

func (slf *Int) Not() *Int

Not 非

func (*Int) Or added in v0.3.4

func (slf *Int) Or(i *Int) *Int

Or 或

func (*Int) Pow added in v0.3.4

func (slf *Int) Pow(i *Int) *Int

func (*Int) PowInt added in v0.3.4

func (slf *Int) PowInt(i int) *Int

func (*Int) PowInt16 added in v0.3.4

func (slf *Int) PowInt16(i int16) *Int

func (*Int) PowInt32 added in v0.3.4

func (slf *Int) PowInt32(i int32) *Int

func (*Int) PowInt64 added in v0.3.4

func (slf *Int) PowInt64(i int64) *Int

func (*Int) PowInt8 added in v0.3.4

func (slf *Int) PowInt8(i int8) *Int

func (*Int) PowUint added in v0.3.4

func (slf *Int) PowUint(i uint) *Int

func (*Int) PowUint16 added in v0.3.4

func (slf *Int) PowUint16(i uint16) *Int

func (*Int) PowUint32 added in v0.3.4

func (slf *Int) PowUint32(i uint32) *Int

func (*Int) PowUint64 added in v0.3.4

func (slf *Int) PowUint64(i uint64) *Int

func (*Int) PowUint8 added in v0.3.4

func (slf *Int) PowUint8(i uint8) *Int

func (*Int) ProportionalCalc added in v0.3.4

func (slf *Int) ProportionalCalc(proportional *Int, formula func(v *Int) *Int) *Int

ProportionalCalc 比例计算,该函数会再 formula 返回值的基础上除以 proportional

  • formula 为计算公式,该公式的参数为调用该函数的 Int 的拷贝

func (*Int) Rsh added in v0.3.4

func (slf *Int) Rsh(i int) *Int

Rsh 右移

func (*Int) Set

func (slf *Int) Set(i *Int) *Int

Set 设置当前 Int 对象的值为 i

Example
package main

import (
	"fmt"
	"github.com/kercylan98/minotaur/utils/huge"
)

func main() {
	var a = huge.NewInt(1234567890)
	var b = huge.NewInt(9876543210)
	fmt.Println(a)
	a.Set(b)
	fmt.Println(a)
}
Output:

1234567890
9876543210

func (*Int) SetBit added in v0.3.4

func (slf *Int) SetBit(i int, v uint) *Int

SetBit 设置二进制位

func (*Int) SetBool added in v0.5.2

func (slf *Int) SetBool(i bool) *Int

SetBool 设置当前 Int 对象的值为 i,当 i 为 true 时,值为 1,当 i 为 false 时,值为 0

func (*Int) SetFloat32 added in v0.5.2

func (slf *Int) SetFloat32(i float32) *Int

SetFloat32 设置当前 Int 对象的值为 i 向下取整后的值

func (*Int) SetFloat64 added in v0.5.2

func (slf *Int) SetFloat64(i float64) *Int

SetFloat64 设置当前 Int 对象的值为 i 向下取整后的值

func (*Int) SetInt

func (slf *Int) SetInt(i int) *Int

SetInt 设置当前 Int 对象的值为 i

func (*Int) SetInt16

func (slf *Int) SetInt16(i int16) *Int

SetInt16 设置当前 Int 对象的值为 i

func (*Int) SetInt32

func (slf *Int) SetInt32(i int32) *Int

SetInt32 设置当前 Int 对象的值为 i

func (*Int) SetInt64

func (slf *Int) SetInt64(i int64) *Int

SetInt64 设置当前 Int 对象的值为 i

func (*Int) SetInt8

func (slf *Int) SetInt8(i int8) *Int

SetInt8 设置当前 Int 对象的值为 i

func (*Int) SetString added in v0.5.2

func (slf *Int) SetString(i string) *Int

SetString 设置当前 Int 对象的值为 i

func (*Int) SetUint

func (slf *Int) SetUint(i uint) *Int

SetUint 设置当前 Int 对象的值为 i

func (*Int) SetUint16

func (slf *Int) SetUint16(i uint16) *Int

SetUint16 设置当前 Int 对象的值为 i

func (*Int) SetUint32

func (slf *Int) SetUint32(i uint32) *Int

SetUint32 设置当前 Int 对象的值为 i

func (*Int) SetUint64

func (slf *Int) SetUint64(i uint64) *Int

SetUint64 设置当前 Int 对象的值为 i

func (*Int) SetUint8

func (slf *Int) SetUint8(i uint8) *Int

SetUint8 设置当前 Int 对象的值为 i

func (*Int) Sign added in v0.3.4

func (slf *Int) Sign() int

Sign 返回数字的符号

  • 1:正数
  • 0:零
  • -1:负数

func (*Int) Sqrt added in v0.3.4

func (slf *Int) Sqrt() *Int

Sqrt 平方根

func (*Int) String

func (slf *Int) String() string

String 转换为 string 类型进行返回

func (*Int) Sub

func (slf *Int) Sub(i *Int) *Int

func (*Int) SubInt

func (slf *Int) SubInt(i int) *Int

func (*Int) SubInt16

func (slf *Int) SubInt16(i int16) *Int

func (*Int) SubInt32

func (slf *Int) SubInt32(i int32) *Int

func (*Int) SubInt64

func (slf *Int) SubInt64(i int64) *Int

func (*Int) SubInt8

func (slf *Int) SubInt8(i int8) *Int

func (*Int) SubUint

func (slf *Int) SubUint(i uint) *Int

func (*Int) SubUint16

func (slf *Int) SubUint16(i uint16) *Int

func (*Int) SubUint32

func (slf *Int) SubUint32(i uint32) *Int

func (*Int) SubUint64

func (slf *Int) SubUint64(i uint64) *Int

func (*Int) SubUint8

func (slf *Int) SubUint8(i uint8) *Int

func (*Int) ToBigint

func (slf *Int) ToBigint() *big.Int

ToBigint 转换为 *big.Int

func (*Int) Xor added in v0.3.4

func (slf *Int) Xor(i *Int) *Int

Xor 异或

Jump to

Keyboard shortcuts

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