Documentation
¶
Index ¶
- Constants
- func CanIntMulOverflow[INT Int](x, y INT) bool
- func CanIntSumOverflow[INT Int](a, b INT) bool
- func MaxInt[T Int]() T
- func MinInt[T Int]() T
- func SumInt[INT Int](a, b INT) (INT, bool)
- type AInt
- type BigInt
- func (i BigInt[INT]) Abs() BigInt[INT]
- func (i BigInt[INT]) Add(n BigInt[INT]) BigInt[INT]
- func (i BigInt[INT]) Compare(o BigInt[INT]) int
- func (i BigInt[INT]) Div(n BigInt[INT]) BigInt[INT]
- func (i BigInt[INT]) FromBigInt(n *big.Int) BigInt[INT]
- func (i BigInt[INT]) IsZero() bool
- func (i BigInt[INT]) Iter() iter.Seq[INT]
- func (i BigInt[INT]) Mul(n BigInt[INT]) BigInt[INT]
- func (i BigInt[INT]) Of(n INT) BigInt[INT]
- func (BigInt[INT]) Parse(raw string) (BigInt[INT], error)
- func (i BigInt[INT]) String() string
- func (i BigInt[INT]) Sub(n BigInt[INT]) BigInt[INT]
- func (i BigInt[INT]) ToBigInt() *big.Int
- func (i BigInt[INT]) ToInt() (INT, bool)
- type Float
- type Int
- type Number
- type UInt
Examples ¶
Constants ¶
View Source
const ErrParseBigInt errorkit.Error = "ErrParseBigInt"
Variables ¶
This section is empty.
Functions ¶
func CanIntMulOverflow ¶
func CanIntSumOverflow ¶
func MaxInt ¶
func MaxInt[T Int]() T
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { _ = mathkit.MaxInt[int8]() // 127 _ = mathkit.MaxInt[int16]() // 32767 _ = mathkit.MaxInt[int32]() // 2147483647 _ = mathkit.MaxInt[int64]() // 9223372036854775807 _ = mathkit.MaxInt[time.Duration]() // time.Duration(9223372036854775807) }
func MinInt ¶
func MinInt[T Int]() T
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { _ = mathkit.MinInt[int8]() // -128 _ = mathkit.MinInt[int16]() // -32768 _ = mathkit.MinInt[int32]() // -2147483648 _ = mathkit.MinInt[int64]() // -9223372036854775808 _ = mathkit.MinInt[time.Duration]() // time.Duration(-9223372036854775808) }
Types ¶
type AInt ¶
type AInt = uint64
type BigInt ¶
type BigInt[INT Int] struct { // contains filtered or unexported fields }
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { var v mathkit.BigInt[time.Duration] v = v.Add(v.Of(24 * time.Hour)) v = v.Mul(v.Of(365)) v = v.Mul(v.Of(1024)) _ = v }
func (BigInt[INT]) Add ¶
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { var v mathkit.BigInt[time.Duration] v = v.Add(v.Of(24 * time.Hour)) }
func (BigInt[INT]) Div ¶
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { var v mathkit.BigInt[time.Duration] v = v.Add(v.Of(24 * time.Hour)) v = v.Div(v.Of(2)) }
func (BigInt[INT]) Iter ¶
Iter produces non-zero integer values ranging from 1 to the maximum or minimum possible integer value. When you add up all these yielded values, they equal the current big integer being iterated over.
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { var v mathkit.BigInt[time.Duration] v = v.Add(v.Of(mathkit.MaxInt[time.Duration]())) v = v.Add(v.Of(mathkit.MaxInt[time.Duration]())) v = v.Add(v.Of(mathkit.MaxInt[time.Duration]())) for n := range v.Iter() { // n will contain a non-zero Int<time.Duration> value, // and the total sum of the iterated n values will be equal to the value of v. _ = n // } }
func (BigInt[INT]) Mul ¶
Example ¶
package main import ( "time" "go.llib.dev/frameless/pkg/mathkit" ) func main() { var v mathkit.BigInt[time.Duration] v = v.Add(v.Of(24 * time.Hour)) v = v.Mul(v.Of(365)) }
type Float ¶
type Float constraints.Float
type Int ¶
type Int constraints.Int
type Number ¶
type Number constraints.Number
type UInt ¶
type UInt constraints.UInt
Click to show internal directories.
Click to hide internal directories.