fixedpoint

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 6 Imported by: 5

Documentation

Overview

Package fixedpoint provides constants, as well as formatting, conversion, and checking functionality for Cadence fixed-point number types

Index

Constants

View Source
const (
	Fix128Scale      = 24
	Fix128MaxBits    = 128
	Fix128LowMaxBits = 64
)
View Source
const Fix64Factor = 100_000_000
View Source
const Fix64Scale = 8
View Source
const Fix64TypeMaxFractional = math.MaxInt64 % Fix64Factor
View Source
const Fix64TypeMaxInt = math.MaxInt64 / Fix64Factor
View Source
const Fix64TypeMinFractional = math.MinInt64 % Fix64Factor
View Source
const Fix64TypeMinInt = math.MinInt64 / Fix64Factor
View Source
const (
	UFix128Scale = Fix128Scale
)
View Source
const UFix64TypeMaxFractional = math.MaxUint64 % uint64(Fix64Factor)
View Source
const UFix64TypeMaxInt = math.MaxUint64 / uint64(Fix64Factor)
View Source
const UFix64TypeMinFractional = 0
View Source
const UFix64TypeMinInt = 0

Variables

View Source
var (
	Fix128FactorAsBigInt = new(big.Int).Exp(
		big.NewInt(10),
		big.NewInt(Fix128Scale),
		nil,
	)

	Fix64ToFix128FactorAsBigInt = new(big.Int).Exp(
		big.NewInt(10),
		big.NewInt(Fix128Scale-Fix64Scale),
		nil,
	)

	Fix128TypeMin = fix.Fix128Min
	Fix128TypeMax = fix.Fix128Max

	Fix128TypeMinBig = Fix128ToBigInt(Fix128TypeMin)
	Fix128TypeMaxBig = Fix128ToBigInt(Fix128TypeMax)

	Fix128TypeMinIntBig, Fix128TypeMinFractionalBig = func() (*big.Int, *big.Int) {
		quotient := new(big.Int)
		remainder := new(big.Int)

		quotient, remainder = quotient.QuoRem(Fix128TypeMinBig, Fix128FactorAsBigInt, remainder)
		remainder = remainder.Abs(remainder)

		return quotient, remainder
	}()

	Fix128TypeMaxIntBig, Fix128TypeMaxFractionalBig = func() (*big.Int, *big.Int) {
		quotient := new(big.Int)
		remainder := new(big.Int)

		quotient, remainder = quotient.QuoRem(Fix128TypeMaxBig, Fix128FactorAsBigInt, remainder)
		remainder = remainder.Abs(remainder)

		return quotient, remainder
	}()
)
View Source
var (
	UFix128FactorAsBigInt = Fix128FactorAsBigInt

	UFix128TypeMin = fix.UFix128Zero
	UFix128TypeMax = fix.UFix128Max

	UFix128TypeMinBig = UFix128ToBigInt(UFix128TypeMin)
	UFix128TypeMaxBig = UFix128ToBigInt(UFix128TypeMax)

	UFix128TypeMinIntBig        = big.NewInt(0)
	UFix128TypeMinFractionalBig = big.NewInt(0)

	UFix128TypeMaxIntBig, UFix128TypeMaxFractionalBig = func() (*big.Int, *big.Int) {
		quotient := new(big.Int)
		remainder := new(big.Int)

		quotient, remainder = quotient.QuoRem(UFix128TypeMaxBig, UFix128FactorAsBigInt, remainder)
		remainder = remainder.Abs(remainder)

		return quotient, remainder
	}()
)
View Source
var Fix64TypeMax = new(big.Int).SetInt64(math.MaxInt64)
View Source
var Fix64TypeMaxFractionalBig = new(big.Int).SetInt64(Fix64TypeMaxFractional)
View Source
var Fix64TypeMaxIntBig = new(big.Int).SetInt64(Fix64TypeMaxInt)
View Source
var Fix64TypeMaxScaledTo128 = new(big.Int).Mul(
	Fix64TypeMax,
	Fix64ToFix128FactorAsBigInt,
)
View Source
var Fix64TypeMin = new(big.Int).SetInt64(math.MinInt64)
View Source
var Fix64TypeMinFractionalBig = new(big.Int).SetInt64(Fix64TypeMinFractional)
View Source
var Fix64TypeMinIntBig = new(big.Int).SetInt64(Fix64TypeMinInt)
View Source
var Fix64TypeMinScaledTo128 = new(big.Int).Mul(
	Fix64TypeMin,
	Fix64ToFix128FactorAsBigInt,
)
View Source
var UFix64TypeMaxFractionalBig = new(big.Int).SetUint64(UFix64TypeMaxFractional)
View Source
var UFix64TypeMaxIntBig = new(big.Int).SetUint64(UFix64TypeMaxInt)
View Source
var UFix64TypeMaxScaledTo128 = new(big.Int).Mul(
	new(big.Int).SetUint64(math.MaxUint64),
	Fix64ToFix128FactorAsBigInt,
)
View Source
var UFix64TypeMinFractionalBig = new(big.Int).SetUint64(UFix64TypeMinFractional)
View Source
var UFix64TypeMinIntBig = new(big.Int).SetUint64(UFix64TypeMinInt)
View Source
var UFix64TypeMinScaledTo128 = new(big.Int).Mul(
	new(big.Int).SetUint64(0),
	Fix64ToFix128FactorAsBigInt,
)

Functions

func CheckRange

func CheckRange(
	negative bool,
	unsignedIntegerValue, fractionalValue,
	minInt, minFractional,
	maxInt, maxFractional *big.Int,
) bool

func ConvertToFixedPointBigInt

func ConvertToFixedPointBigInt(
	negative bool,
	unsignedInteger *big.Int,
	fractional *big.Int,
	scale uint,
	targetScale uint,
) *big.Int

func Fix128FromBigInt added in v1.7.0

func Fix128FromBigInt(value *big.Int) fix.Fix128

func Fix128FromIntAndScale added in v1.7.0

func Fix128FromIntAndScale(integer, scale int64) fix.Fix128

func Fix128ToBigEndianBytes added in v1.7.0

func Fix128ToBigEndianBytes(fix128 fix.Fix128) []byte

func Fix128ToBigInt added in v1.7.0

func Fix128ToBigInt(fix128 fix.Fix128) *big.Int

func NewFix128 added in v1.7.0

func NewFix128(
	negative bool,
	unsignedInteger *big.Int,
	fractional *big.Int,
	parsedScale uint,
) (
	*big.Int,
	error,
)

func NewFix64

func NewFix64(
	negative bool,
	unsignedInteger *big.Int,
	fractional *big.Int,
	parsedScale uint,
) (
	*big.Int,
	error,
)

func NewUFix128 added in v1.7.0

func NewUFix128(
	unsignedInteger *big.Int,
	fractional *big.Int,
	parsedScale uint,
) (
	*big.Int,
	error,
)

func NewUFix64

func NewUFix64(
	unsignedInteger *big.Int,
	fractional *big.Int,
	parsedScale uint,
) (
	*big.Int,
	error,
)

func ParseFix128 added in v1.7.0

func ParseFix128(s string) (*big.Int, error)

func ParseFix64

func ParseFix64(s string) (*big.Int, error)

func ParseUFix128 added in v1.7.0

func ParseUFix128(s string) (*big.Int, error)

func ParseUFix64

func ParseUFix64(s string) (*big.Int, error)

func UFix128FromBigInt added in v1.7.0

func UFix128FromBigInt(value *big.Int) fix.UFix128

func UFix128ToBigEndianBytes added in v1.7.0

func UFix128ToBigEndianBytes(fix128 fix.UFix128) []byte

func UFix128ToBigInt added in v1.7.0

func UFix128ToBigInt(value fix.UFix128) *big.Int

Types

This section is empty.

Jump to

Keyboard shortcuts

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