misc

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package misc contains miscellaneous decimal routes.

Index

Constants

View Source
const (
	// Radix is the base in which decimal arithmetic is effected.
	Radix = 10

	// IsCanonical is true since Big decimals are always normalized.
	IsCanonical = true
)

Variables

This section is empty.

Functions

func Canonical

func Canonical(z, x *decimal.Big) *decimal.Big

Canonical sets z to the canonical form of z.

Since Big values are always canonical, it's identical to Copy.

func CmpTotal

func CmpTotal(x, y *decimal.Big) int

CmpTotal compares x and y in a manner similar to the Big.Cmp, but allows ordering of all abstract representations.

In particular, this means NaN values have a defined ordering. From lowest to highest the ordering is:

-NaN
-sNaN
-Infinity
-127
-1.00
-1
-0.000
-0
+0
+1.2300
+1.23
+1E+9
+Infinity
+sNaN
+NaN

func CmpTotalAbs

func CmpTotalAbs(x, y *decimal.Big) int

CmpTotalAbs is like CmpTotal but instead compares the absolute values of x and y.

func CopyAbs

func CopyAbs(z, x *decimal.Big) *decimal.Big

CopyAbs is like Abs, but no flags are changed and the result is not rounded.

func CopyNeg

func CopyNeg(z, x *decimal.Big) *decimal.Big

CopyNeg is like Neg, but no flags are changed and the result is not rounded.

func Mantissa

func Mantissa(x *decimal.Big) (uint64, bool)

Mantissa returns the mantissa of x. If the mantissa cannot fit into a uint64 or x is not finite, the bool will be false. This may be used to convert a decimal representing a monetary to its most basic unit (e.g., $123.45 to 12345 cents.)

func Max

func Max(x ...*decimal.Big) *decimal.Big

Max returns the greater of the provided values.

The result is undefined if no values are are provided.

func MaxAbs

func MaxAbs(x ...*decimal.Big) *decimal.Big

MaxAbs returns the greater of the absolute value of the provided values.

The result is undefined if no values are provided.

func Min

func Min(x ...*decimal.Big) *decimal.Big

Min returns the lesser of the provided values.

The result is undefined if no values are are provided.

func MinAbs

func MinAbs(x ...*decimal.Big) *decimal.Big

MinAbs returns the lesser of the absolute value of the provided values. The result is undefined if no values are provided.

func NextMinus

func NextMinus(z, x *decimal.Big) *decimal.Big

NextMinus sets z to the smallest representable number that's smaller than x and returns z. If x is negative infinity the result will be negative infinity. If the result is zero its sign will be negative and its scale will be MinScale.

func NextPlus

func NextPlus(z, x *decimal.Big) *decimal.Big

NextPlus sets z to the largest representable number that's larger than x and returns z. If x is positive infinity the result will be positive infinity. If the result is zero it will be positive and its scale will be MaxScale.

func SameQuantum

func SameQuantum(x, y *decimal.Big) bool

SameQuantum returns true if x and y have the same exponent (scale).

func SetSignbit

func SetSignbit(z *decimal.Big, sign bool) *decimal.Big

SetSignbit sets z to -z if sign is true, otherwise to +z.

Types

This section is empty.

Jump to

Keyboard shortcuts

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