arith

package
v0.0.0-...-00de7ca Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package arith provides performance-sensitive arithmetic operations.

Index

Constants

View Source
const (
	// PowTabLen is the largest cached power for integers.
	PowTabLen = 20

	// BigPowTabLen is the largest cached power for *big.Ints.
	BigPowTabLen = 1e5
)
View Source
const (
	MaxInt = 1<<(intSize-1) - 1
)
View Source
const MaxLength = 20

Variables

This section is empty.

Functions

func Abs

func Abs(x int64) uint64

Abs returns the absolute value of x.

func Add

func Add(z, x *big.Int, y uint64) *big.Int

Add sets z to x + y and returns z.

x is assumed to be unsigned.

func BigLength

func BigLength(x *big.Int) int

BigLength returns the number of digits in x.

func BigPow10

func BigPow10(n uint64) *big.Int

BigPow10 computes 10**n.

The returned *big.Int must not be modified.

func Cmp

func Cmp(x, y uint64) int

Cmp compares x and y and returns

-1 if x  < 0
 0 if x == 0
+1 if x  > 0

func CmpBits

func CmpBits(x, y []big.Word) (r int)

CmpBits compares x and y.

func CmpShift

func CmpShift(x, y, shift uint64) int

CmpShift compares x and y*shift.

func Length

func Length(x uint64) int

Length returns the number of digits in x.

func Mul

func Mul(z, x *big.Int, y uint64) *big.Int

Mul sets z to x * y and returns z.

x is assumed to be unsigned.

func MulBigPow10

func MulBigPow10(z, x *big.Int, n uint64) *big.Int

MulBigPow10 sets z to x * 10**n and returns z.

func MulPow10

func MulPow10(x uint64, n uint64) (uint64, bool)

MulPow10 computes x * 10**n and a bool indicating whether the multiplcation was successful.

func Pow10

func Pow10(e uint64) (uint64, bool)

Pow10 returns 10**e and a boolean indicating whether the result fits into a uint64.

func Pow10Int

func Pow10Int(e uint64) (int64, bool)

Pow10Int returns 10**e and a boolean indicating whether the result fits into an int64.

func PowOfTen

func PowOfTen(x uint64) bool

PowOfTen reports whether x is a power of 10.

func PowOfTenBig

func PowOfTenBig(x *big.Int) bool

PowOfTenBig reports whether x is a power of 10.

func Safe

func Safe(e uint64) bool

func Set

func Set(z *big.Int, z1, z0 uint64) *big.Int

Set sets z to the 128-bit integer represented by z1 and z0.

func Sub

func Sub(z, x *big.Int, y uint64) *big.Int

Sub sets z to x - y and returns z.

x is assumed to be unsigned.

func Words

func Words(x uint64) []big.Word

Words returns a little-endian slice of big.Words representing the uint64.

Types

This section is empty.

Jump to

Keyboard shortcuts

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