bpmath

package
v6.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package bpmath provides types and functions for doing basis point operations with math.Int. So, the result is always math.Int, and follows the Go rounding semantic for integer nubmer: rounds towards zero.

Index

Constants

View Source
const (
	One  = 10000
	Half = One / 2
	Zero = 0
)

Variables

This section is empty.

Functions

func Mul

func Mul[T BP | FixedBP | int](a cmath.Int, b T) cmath.Int

Mul returns a * b_basis_points rounding towards zero. Contract: b in [0, MaxUint32]

func MulDec

func MulDec[T BP | FixedBP | int](a sdk.Dec, b T) sdk.Dec

MulDec returns a * b_basis_points rounding towards zero. Contract: b in [0, MaxUint32]

Types

type BP

type BP uint32

BP represents values in basis points. Maximum value is 2^32-1. Note: BP operations should not be chained - this causes precision losses.

func FromQuo

func FromQuo(dividend, divisor cmath.Int, rounding Rounding) BP

FromQuo returns a/b in basis points. Contract: a>=0 and b > 0. Panics if a/b >= MaxUint32/10'000 or if b==0.

func (BP) Mul

func (bp BP) Mul(a cmath.Int) cmath.Int

Mul return a*bp rounding towards zero.

func (BP) MulDec

func (bp BP) MulDec(a sdk.Dec) sdk.Dec

MulDec return a*bp rounding towards zero.

func (BP) ToDec

func (bp BP) ToDec() sdk.Dec

type FixedBP

type FixedBP uint32

FixedBP assures that all operations are in 0-10'000 range Note: FixedBP operations should not be chained - this causes precision loses.

func FixedFromQuo

func FixedFromQuo(dividend, divisor math.Int, rounding Rounding) FixedBP

FixedFromQuo returns a/b in basis points. Returns 10'000 if a >= b; Contract: a>=0 and b > 0. Panics if b==0.

func (FixedBP) Mul

func (bp FixedBP) Mul(a math.Int) math.Int

Mul return a*bp rounding towards zero.

func (FixedBP) MulDec

func (bp FixedBP) MulDec(a sdk.Dec) sdk.Dec

MulDec return a*bp rounding towards zero.

func (FixedBP) ToDec

func (bp FixedBP) ToDec() sdk.Dec

type Rounding

type Rounding uint
const (
	DOWN Rounding = iota
	UP
)

Jump to

Keyboard shortcuts

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