mathUtils

package
v0.0.0-...-2e001e6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package mathUtils provides utilities regarding mathematics.

Index

Constants

View Source
const MaxInt = int(^uint(0) >> 1)

MaxInt is the maximum int value

View Source
const MaxUint = ^uint(0)

MaxUint is the maximum uint value

View Source
const MinInt = -(MaxInt - 1)

MinInt is the minimum int value

View Source
const MinUint = 0

MinUint is the minimum uint value (0)

Variables

View Source
var FourFifths = NewFraction(4, 5)

FourFifths is 4/5

View Source
var One = NewFraction(1, 1)

One is 1/1

View Source
var OneFifth = NewFraction(1, 5)

OneFifth is 1/5

View Source
var OneHalf = NewFraction(1, 2)

OneHalf is 1/2

View Source
var OneQuarter = NewFraction(1, 4)

OneQuarter is 1/4

View Source
var OneThird = NewFraction(1, 3)

OneThird is 1/3

View Source
var ThreeFifths = NewFraction(3, 5)

ThreeFifths is 3/5

View Source
var ThreeQuarters = NewFraction(3, 4)

ThreeQuarters is 3/4

View Source
var TwoFifths = NewFraction(2, 5)

TwoFifths is 2/5

View Source
var TwoQuarters = NewFraction(2, 4)

TwoQuarters is 2/4

View Source
var TwoThirds = NewFraction(2, 3)

TwoThirds is 2/3

View Source
var Zero = NewFraction(0, 1)

Zero is 0/1

Functions

This section is empty.

Types

type Fraction

type Fraction struct {
	// contains filtered or unexported fields
}

Fraction represents a fraction which holds both a numerator and a denominator Definitely needs testing!

func GetFraction

func GetFraction(numerator, denominator int) *Fraction

GetFraction creates a Fraction instance with the 2 parts of a fraction Y/Z.

func GetReducedFraction

func GetReducedFraction(numerator, denominator int) *Fraction

GetReducedFraction creates a reduced Fraction instance with the 2 parts of a fraction Y/Z. For example, if the input parameters represent 2/4, then the created fraction will be 1/2.

func GetWholeFraction

func GetWholeFraction(whole, numerator, denominator int) *Fraction

GetWholeFraction creates a Fraction instance with the 3 parts of a fraction X Y/Z.

func NewFraction

func NewFraction(numerator, denominator int) *Fraction

NewFraction constructs a Fraction instance with the 2 parts of a fraction Y/Z.

func (*Fraction) Abs

func (f *Fraction) Abs() *Fraction

Abs gets a fraction that is the positive equivalent of this One. More precisely: fraction >= 0 ? this : -fraction) The returned fraction is not reduced.

func (*Fraction) DivideBy

func (f *Fraction) DivideBy(ff *Fraction) *Fraction

DivideBy divides the value of this fraction by another.

func (*Fraction) Equals

func (f *Fraction) Equals(f2 *Fraction) bool

Equals checks if Two Fraction are the same

func (*Fraction) Float32Value

func (f *Fraction) Float32Value() float32

Float32Value gets the fraction as a float32. This calculates the fraction as the numerator divided by denominator.

func (*Fraction) Float64Value

func (f *Fraction) Float64Value() float64

Float64Value gets the fraction as a float64. This calculates the fraction as the numerator divided by denominator.

func (*Fraction) GetDenominator

func (f *Fraction) GetDenominator() int

GetDenominator gets the denominator part of the fraction.

func (*Fraction) GetNumerator

func (f *Fraction) GetNumerator() int

GetNumerator gets the numerator part of the fraction. This method may return a value greater than the denominator, an improper fraction, such as the seven in 7/4.

func (*Fraction) GetProperNumerator

func (f *Fraction) GetProperNumerator() int

GetProperNumerator gets the proper numerator, always positive. An improper fraction 7/4 can be resolved into a proper One, 1 3/4. This method returns the 3 from the proper fraction. If the fraction is negative such as -7/4, it can be resolved into -1 3/4, so this method returns the positive proper numerator, 3.

func (*Fraction) GetProperWhole

func (f *Fraction) GetProperWhole() int

GetProperWhole gets the proper whole part of the fraction. An improper fraction 7/4 can be resolved into a proper One, 1 3/4. This method returns the 1 from the proper fraction. If the fraction is negative such as -7/4, it can be resolved into -1 3/4, so this method returns the positive whole part -1.

func (*Fraction) IntValue

func (f *Fraction) IntValue() int

IntValue gets the fraction as an int. This returns the whole number part of the fraction.

func (*Fraction) Invert

func (f *Fraction) Invert() *Fraction

Invert gets a fraction that is the inverse (1/fraction) of this One. The returned fraction is not reduced.

func (*Fraction) MultiplyBy

func (f *Fraction) MultiplyBy(ff *Fraction) *Fraction

MultiplyBy multiplies the value of this fraction by another, returning the result in reduced form.

func (*Fraction) Negate

func (f *Fraction) Negate() *Fraction

Negate gets a fraction that is the negative (-fraction) of this One. The returned fraction is not reduced.

func (*Fraction) Pow

func (f *Fraction) Pow(power int) *Fraction

Pow get a fraction that is powered by a specific value

func (*Fraction) Reduce

func (f *Fraction) Reduce() *Fraction

Reduce reduce the fraction to the smallest values for the numerator and denominator, returning the result. For example, if this fraction represents 2/4, then the result will be 1/2.

Jump to

Keyboard shortcuts

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