Documentation
¶
Overview ¶
Package mathUtils provides utilities regarding mathematics.
Index ¶
- Constants
- Variables
- type Fraction
- func (f *Fraction) Abs() *Fraction
- func (f *Fraction) DivideBy(ff *Fraction) *Fraction
- func (f *Fraction) Equals(f2 *Fraction) bool
- func (f *Fraction) Float32Value() float32
- func (f *Fraction) Float64Value() float64
- func (f *Fraction) GetDenominator() int
- func (f *Fraction) GetNumerator() int
- func (f *Fraction) GetProperNumerator() int
- func (f *Fraction) GetProperWhole() int
- func (f *Fraction) IntValue() int
- func (f *Fraction) Invert() *Fraction
- func (f *Fraction) MultiplyBy(ff *Fraction) *Fraction
- func (f *Fraction) Negate() *Fraction
- func (f *Fraction) Pow(power int) *Fraction
- func (f *Fraction) Reduce() *Fraction
Constants ¶
const MaxInt = int(^uint(0) >> 1)
MaxInt is the maximum int value
const MaxUint = ^uint(0)
MaxUint is the maximum uint value
const MinInt = -(MaxInt - 1)
MinInt is the minimum int value
const MinUint = 0
MinUint is the minimum uint value (0)
Variables ¶
var FourFifths = NewFraction(4, 5)
FourFifths is 4/5
var One = NewFraction(1, 1)
One is 1/1
var OneFifth = NewFraction(1, 5)
OneFifth is 1/5
var OneHalf = NewFraction(1, 2)
OneHalf is 1/2
var OneQuarter = NewFraction(1, 4)
OneQuarter is 1/4
var OneThird = NewFraction(1, 3)
OneThird is 1/3
var ThreeFifths = NewFraction(3, 5)
ThreeFifths is 3/5
var ThreeQuarters = NewFraction(3, 4)
ThreeQuarters is 3/4
var TwoFifths = NewFraction(2, 5)
TwoFifths is 2/5
var TwoQuarters = NewFraction(2, 4)
TwoQuarters is 2/4
var TwoThirds = NewFraction(2, 3)
TwoThirds is 2/3
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 ¶
GetFraction creates a Fraction instance with the 2 parts of a fraction Y/Z.
func GetReducedFraction ¶
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 ¶
GetWholeFraction creates a Fraction instance with the 3 parts of a fraction X Y/Z.
func NewFraction ¶
NewFraction constructs a Fraction instance with the 2 parts of a fraction Y/Z.
func (*Fraction) Abs ¶
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) Float32Value ¶
Float32Value gets the fraction as a float32. This calculates the fraction as the numerator divided by denominator.
func (*Fraction) Float64Value ¶
Float64Value gets the fraction as a float64. This calculates the fraction as the numerator divided by denominator.
func (*Fraction) GetDenominator ¶
GetDenominator gets the denominator part of the fraction.
func (*Fraction) GetNumerator ¶
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 ¶
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 ¶
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 ¶
IntValue gets the fraction as an int. This returns the whole number part of the fraction.
func (*Fraction) Invert ¶
Invert gets a fraction that is the inverse (1/fraction) of this One. The returned fraction is not reduced.
func (*Fraction) MultiplyBy ¶
MultiplyBy multiplies the value of this fraction by another, returning the result in reduced form.
func (*Fraction) Negate ¶
Negate gets a fraction that is the negative (-fraction) of this One. The returned fraction is not reduced.