Fractions is a Go library that adds fraction-like capabilities to Go. If you want to install Fractions simply run the command shown below in your terminal.
go get github.com/TimoKats/fractions
Next, after installing Fractions you can import (and test) the installation with the code shown below. If this outputs 1 2/3
then the installation has been completed correctly.
package main
import (
"github.com/TimoKats/fractions"
)
func main() {
y1 := fractions.FloatToFrac(1.67)
fractions.PrintFrac(y1)
}
This library saves fractions as objects/structs (called frac) and has functions for: printing, setting, getting, formatting and computing. Hereby a short overview of them all.
- PrintFrac(frac *frac)
- PrintNumerator(frac *frac)
- PrintDenominator(frac *frac)
- PrintInteger(frac *frac)
- MakeFrac(integer int, numerator int, denominator int)
- SetNumerator(frac *frac, value int)
- SetDenominator(frac *frac, value int)
- SetInteger(frac *frac, value int)
- GetNumerator(frac *frac)
- GetDenominator(frac *frac)
- GetInteger(frac *frac)
- FloatToFrac(value float64)
- FracToFloat(frac *frac)
- FormatFracOnly(frac *frac)
- FormatSimplify(frac *frac)
- SumFrac(frac1 *frac, frac2 *frac)
- SumInt(frac1 *frac, frac2 *frac)
- SubtractFrac(frac1 *frac, frac2 *frac)
- SubtractInt(frac1 *frac, frac2 *frac)
- SubtractInt(frac1 *frac, value int)
- DivideFrac(frac1 *frac, frac2 *frac)
- DivideInt(frac1 *frac, value int)
- PowerFrac(frac1 *frac, value int)