decimal

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: MIT Imports: 1 Imported by: 1

README

decimal

Go Reference

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Zero = &Decimal{}

Functions

func IsZero

func IsZero(d *Decimal) bool

IsZero returns true if d == 0 or -0.

func SetPrecision

func SetPrecision(p uint32)

SetPrecision sets the precision to p.

func Text

func Text(d *Decimal) string

Text converts the floating-point number d to a string according to the format -dddd.dddd, no exponent.

The 'f' format has the possibility of displaying precision that is not present in the Decimal when it appends zeros.

Types

type Decimal

type Decimal struct {
	apd.Decimal
}

func New

func New(c int64, e int32) *Decimal

New creates a new decimal with the given coefficient and exponent.

func NewFromString

func NewFromString(s string) (*Decimal, error)

NewFromString creates a new decimal from s.

func (*Decimal) Abs

func (x *Decimal) Abs() *Decimal

Abs sets d to |x| (the absolute value of x).

func (*Decimal) Add

func (x *Decimal) Add(y *Decimal) *Decimal

Add sets d to the sum x+y.

func (*Decimal) Cbrt

func (x *Decimal) Cbrt() *Decimal

Cbrt sets d to the cube root of x.

func (*Decimal) Ceil

func (x *Decimal) Ceil() *Decimal

Ceil sets d to the smallest integer >= x.

func (*Decimal) Div

func (x *Decimal) Div(y *Decimal) *Decimal

Div sets d to the quotient x/y for y != 0.

func (*Decimal) DivInt

func (x *Decimal) DivInt(y *Decimal) *Decimal

DivInt sets d to the integer part of the quotient x/y.

func (*Decimal) DivRem

func (x *Decimal) DivRem(y *Decimal) *Decimal

DivRem sets d to the remainder part of the quotient x/y.

func (*Decimal) Equal

func (x *Decimal) Equal(y *Decimal) bool

Equal compares x and y and returns true if x == y.

func (*Decimal) Floor

func (x *Decimal) Floor() *Decimal

Floor sets d to the largest integer <= x.

func (*Decimal) GreaterThan

func (x *Decimal) GreaterThan(y *Decimal) bool

GreaterThan compares x and y and returns true if x > y.

func (*Decimal) LessThan

func (x *Decimal) LessThan(y *Decimal) bool

LessThan compares x and y and returns true if x < y.

func (*Decimal) Mul

func (x *Decimal) Mul(y *Decimal) *Decimal

Mul sets d to the product x*y.

func (*Decimal) Neg

func (x *Decimal) Neg() *Decimal

Neg sets d to -x.

func (*Decimal) Pow

func (x *Decimal) Pow(y *Decimal) *Decimal

Pow sets d = x**y.

func (*Decimal) Quantize added in v1.0.0

func (x *Decimal) Quantize(exp int32) *Decimal

Quantize adjusts and rounds x as necessary so it is represented with exponent exp and stores the result in d.

func (*Decimal) Sqrt

func (x *Decimal) Sqrt() *Decimal

Sqrt sets d to the square root of x.

func (*Decimal) Sub

func (x *Decimal) Sub(y *Decimal) *Decimal

Sub sets d to the difference x-y.

Jump to

Keyboard shortcuts

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