intmath

package module
v0.0.0-...-1cd09d9 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 3 Imported by: 0

README

intmath

intmath implements some useful integer math functions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[V constraints.Signed](n V) V

Abs(n) computes the absolute value of n, without branching.

func Binomial

func Binomial[V constraints.Unsigned](n, k V) (uint64, bool)

Binomial(n, k) == ‹(n k), false›. Unless the result overflows uint64, in which case it returns ‹0, true›.

func CeilLog10

func CeilLog10[V constraints.Unsigned](u V) V

CeilLog10(u) returns ⌈log₁₀u⌉.

If u is 0, anything might happen 🤷

func CeilLog2

func CeilLog2[V constraints.Unsigned](u V) V

CeilLog2(u) returns ⌈log₂u⌉.

If u is 0, anything might happen 🤷

func FloorLog10

func FloorLog10[V constraints.Unsigned](u V) V

FloorLog10(u) returns ⌊log₁₀u⌋

If u is 0, anything might happen 🤷

func FloorLog2

func FloorLog2[V constraints.Unsigned](u V) V

FloorLog10(u) returns ⌊log₂u⌋

If u is 0, anything might happen 🤷

func Len

func Len[V constraints.Unsigned](u V) V

Len(u) returns the length of the base-10 string of u.

func Pow

func Pow[V constraints.Unsigned](m, n V) V

Pow(m, n) == mⁿ

func PowX

func PowX[V constraints.Unsigned](m, n V) (pow uint64, overflowed bool)

PowX(m, n) == ‹mⁿ, false› as long as it fits in a uint64. As soon as it overflows it returns ‹0, true›.

func Sqrt

func Sqrt[V constraints.Unsigned](n V) V

Sqrt(u) returns √u

NOTE the current implementation uses floating point as that is implemented in hardware in most places (see SqrtI and associated benchmarks in the tests). This might change if somebody points me to a faster version.

Types

This section is empty.

Jump to

Keyboard shortcuts

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