arith

package
v0.0.0-...-7b8028b Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 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
)

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 Add64

func Add64(x, y uint64) (sum, carryOut uint64)

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 Mul64

func Mul64(x, y uint64) (hi, lo uint64)

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 returns strue if x is a power of 10.

func PowOfTenBig

func PowOfTenBig(x *big.Int) bool

PowOfTenBig returns true if 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 Sub64

func Sub64(x, y uint64) (diff, borrowOut uint64)

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