math

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigFloatToBigInt

func BigFloatToBigInt(bf *big.Float) (*big.Int, error)

BigFloatToBigInt converts big.Float values to big.Int values. This function is required because big.NewInt() simply casts to uint64, and is thus bounded by that type's maximum size, i.e. math.MaxUint64 or 18446744073709551615. To get around this, we use the Int() method on big.Float to directly store large values into a big.Int.

func FromOrdinal added in v0.5.0

func FromOrdinal(s string) (int, error)

FromOrdinal will return the integral form of the caller- supplied ordinal string, e.g., FromOrdinal("11th") will return 11, with err set in case a parse error occurs.

func Ordinal added in v0.5.0

func Ordinal[T constraints.Integer](n T) string

Ordinal converts the generic integer type to a string ordinal, e.g., Ordinal(3) returns "3rd". Although any integeral type is accepted, internally it is treated as an int because the mod operator cannot be used with generically constrained types. Thus, whatever is passed in is converted to an int. Moreover, the absolute valus is taken, so Ordinal(-1) will return "1st".

func Roundup added in v0.4.0

func Roundup(f float64) float64

Roundup returns the smallest number, specified to 1 decimal place, that is equal to or higher than its input. Roundup(4.02) returns 4.1, while Roundup(4.00) returns 4.0.

Types

This section is empty.

Jump to

Keyboard shortcuts

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