rational

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 5 Imported by: 0

README

Rational

GoDev Build Status Coverage Status Go Report Card Deepsource.io Card

Utilties for rational number calculation, parsing and manipulation for Golang.

Inspired by (ported from) original ffmpeg/libav AVRational struct.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Rational0 represents Nil Rational.
	Rational0 = Rational{0, 0}

	// Rational100 represents completed Rational.
	Rational100 = Rational{100, 100}
)
View Source
var (
	// ErrWrongPartsNumber indicates parsing error
	// because of wrong parts number in raw string.
	ErrWrongPartsNumber error = errors.New("got wrong string parts number")

	// ErrParseNum indicates parsing numerator error.
	ErrParseNum error = errors.New("failed parse numerator")

	// ErrParseDen indicates parsing denumerator error.
	ErrParseDen error = errors.New("failed parse denumerator")
)

Functions

This section is empty.

Types

type Rational

type Rational struct {
	Num uint64 `json:"num" yaml:"num" bson:"num"`
	Den uint64 `json:"den" yaml:"den" bson:"den"`
}

Rational number numerator/denominator.

func NewRational

func NewRational(v string) (Rational, error)

NewRational parses raw string and returns Rational.

func (Rational) Float64

func (r Rational) Float64() float64

Float64 returns float64 representation.

func (Rational) IsNil

func (r Rational) IsNil() bool

IsNil checks if Rational is nil.

func (Rational) MarshalJSON

func (r Rational) MarshalJSON() ([]byte, error)

MarshalJSON implements json Marshaler.

func (Rational) MarshalYAML

func (r Rational) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml Marshaler.

func (Rational) Percent

func (r Rational) Percent() float64

Percent returns percentage representation. e.g. 1/4 is 25%.

func (Rational) Reverse

func (r Rational) Reverse() Rational

Reverse returns reversed Rational.

func (Rational) String

func (r Rational) String() string

String returns string representation.

func (Rational) StringAlt added in v0.0.2

func (r Rational) StringAlt() string

String returns string representation with sepAlt.

func (Rational) StringAlt2 added in v0.0.2

func (r Rational) StringAlt2() string

String returns string representation with sepAlt.

func (*Rational) Unmarshal

func (r *Rational) Unmarshal(fn func(interface{}) error) error

Unmarshal is generic Unmarshaler. For example to use with GetBSON.

func (*Rational) UnmarshalJSON

func (r *Rational) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json Unmarshaler.

func (*Rational) UnmarshalYAML

func (r *Rational) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml Unmarshaler.

Jump to

Keyboard shortcuts

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