bigfloat

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToNearestEven big.RoundingMode = iota // == IEEE 754-2008 roundTiesToEven
	ToNearestAway                         // == IEEE 754-2008 roundTiesToAway
	ToZero                                // == IEEE 754-2008 roundTowardZero
	AwayFromZero                          // no IEEE 754-2008 equivalent
	ToNegativeInf                         // == IEEE 754-2008 roundTowardNegative
	ToPositiveInf                         // == IEEE 754-2008 roundTowardPositive
)

These constants define supported rounding modes.

View Source
const AutoPrec = 512 // 256 -> decimal 32   512 -> decimal 78

Variables

This section is empty.

Functions

This section is empty.

Types

type BigFloat

type BigFloat struct {
	// contains filtered or unexported fields
}
var ZERO BigFloat

func (*BigFloat) Abs

func (bf *BigFloat) Abs(a BigFloat)

func (*BigFloat) Add

func (bf *BigFloat) Add(a BigFloat, b BigFloat)

func (*BigFloat) BF

func (bf *BigFloat) BF() big.Float

func (*BigFloat) Ceil added in v0.5.7

func (bf *BigFloat) Ceil() (*BigFloat, error)

func (*BigFloat) Cmp

func (bf *BigFloat) Cmp(a BigFloat) int

func (*BigFloat) Convert added in v0.5.7

func (bf *BigFloat) Convert(f *big.Float) error

func (*BigFloat) Copy added in v0.5.7

func (bf *BigFloat) Copy(newBf *BigFloat) error

func (*BigFloat) CreateFromString

func (bf *BigFloat) CreateFromString(s string, mode big.RoundingMode) error

func (*BigFloat) Div

func (bf *BigFloat) Div(a BigFloat, b BigFloat)

func (*BigFloat) Float added in v0.5.7

func (bf *BigFloat) Float() *big.Float

func (*BigFloat) Floor added in v0.5.7

func (bf *BigFloat) Floor() (*BigFloat, error)

func (BigFloat) MarshalJSON

func (bf BigFloat) MarshalJSON() ([]byte, error)

@todo xml protobuf ...

func (*BigFloat) Mul

func (bf *BigFloat) Mul(a BigFloat, b BigFloat)

func (*BigFloat) Round added in v0.5.7

func (bf *BigFloat) Round(decimal uint, roundType RoundType) (*BigFloat, error)
func (bf *BigFloat) roundDown(decimal uint) (*BigFloat, error) {
	var tmp BigFloat
	if err := bf.Copy(&tmp); err != nil {
		return nil, err
	}
	parts := strings.Split(tmp.String(), ".")
	normalPart := parts[0]
	decimalPart := parts[1]

	// if provide decimal is greater than the real decimal, then there isn't any precision problem, so directly return
	if int(decimal) > len(decimalPart) {
		return bf, nil
	}

	newDecimalPart := decimalPart[:decimal]
	lastDecimal, err := strconv.ParseUint(decimalPart[decimal:decimal+1], 10, 32)
	if err != nil {
		return nil, err
	}

	// create roundDown with RoundDown
	roundDownStr := normalPart + "." + newDecimalPart
	var roundDown BigFloat
	if err := roundDown.CreateFromString(roundDownStr, ToNearestEven); err != nil {
		return nil, err
	}
}

func (*BigFloat) Scan

func (bf *BigFloat) Scan(src interface{}) error

func (*BigFloat) SetInt added in v0.5.7

func (bf *BigFloat) SetInt(i *bigint.BigInt, mode big.RoundingMode) error

func (*BigFloat) String

func (bf *BigFloat) String() string

func (*BigFloat) Sub

func (bf *BigFloat) Sub(a BigFloat, b BigFloat)

func (*BigFloat) UnmarshalJSON added in v0.6.5

func (bf *BigFloat) UnmarshalJSON(src []byte) error

func (BigFloat) Value

func (bf BigFloat) Value() (driver.Value, error)

type RoundType added in v0.5.7

type RoundType byte
const (
	RoundUpAlways RoundType = iota
	RoundDown
	RoundUpAuto
)

Jump to

Keyboard shortcuts

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