ix

package
v0.0.0-...-d78bf3b Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package ix contains small integer arithmetic functions in the style of the standard `math` package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T signed](x T) T

Abs returns the absolute value of x.

func CeilDiv

func CeilDiv[T integer](a, b T) T

CeilDiv returns the result of the integer division a / b except always rounded up.

func Concat

func Concat[T integer](a, b T) T

Concat returns the concatenation of two (assumed nonnegative) integer values. For example, ix.Concat(12, 345) == 12345.

func FloorDiv

func FloorDiv[T integer](a, b T) T

FloorDiv returns the result of the integer division a / b except always rounded down, even for negative numbers.

func GCD

func GCD[T integer](a, b T) T

GCD returns the greatest common divisor of the two arguments.

func LCM

func LCM[T integer](a, b T) T

LCM returns the least common multiple of the two arguments.

func Len

func Len[T integer](x T) (n int)

Len returns the number of (decimal) digits in an (assumed nonnegative) integer. Zero is considered to have a length of 0.

func Pow

func Pow[T integer](base, exp T) T

Pow calculates the exponentiation operator for positive integer powers.

func RatSign

func RatSign(p, q int) int

func SLen

func SLen[T integer](x T) (n int)

SLen returns the number of (decimal) digits in an integer, including one for sign. Zero is considered to have a length of 1 as well. This is the print width of the integer.

func Sign

func Sign[T signed](x T) T

Sign returns -1, 0 or 1 if x is less than, equal, or greater than zero, respectively.

func Sqrt

func Sqrt(y int) int

Sqrt returns the integer square root of y. For a nonnegative argument, it is the floor of the mathematical square root. Panics for negative numbers.

Types

type Rat

type Rat struct {
	P, Q int
}

func RatI

func RatI(n int) Rat

func RatOf

func RatOf(p, q int) Rat

func RatU

func RatU(p, q int) Rat

func (Rat) Add

func (r Rat) Add(s Rat) Rat

func (Rat) AddI

func (r Rat) AddI(n int) Rat

func (Rat) Ceil

func (r Rat) Ceil() int

func (Rat) Compare

func (r Rat) Compare(s Rat) int

func (Rat) DivI

func (r Rat) DivI(n int) Rat

func (Rat) Floor

func (r Rat) Floor() int

func (Rat) IsInt

func (r Rat) IsInt() bool

func (Rat) IsValid

func (r Rat) IsValid() bool

func (Rat) Mul

func (r Rat) Mul(s Rat) Rat

func (Rat) MulI

func (r Rat) MulI(n int) Rat

func (Rat) MulIU

func (r Rat) MulIU(n int) Rat

func (Rat) Sub

func (r Rat) Sub(s Rat) Rat

func (Rat) SubI

func (r Rat) SubI(n int) Rat

Jump to

Keyboard shortcuts

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