TimoKats / fractions

Go library that adds fraction-like capabilities to Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fractions logo
License: MIT Donate Status


Getting started

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)
}

Functionalities

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.

print functions

  • PrintFrac(frac *frac)
  • PrintNumerator(frac *frac)
  • PrintDenominator(frac *frac)
  • PrintInteger(frac *frac)

set functions

  • MakeFrac(integer int, numerator int, denominator int)
  • SetNumerator(frac *frac, value int)
  • SetDenominator(frac *frac, value int)
  • SetInteger(frac *frac, value int)

get functions

  • GetNumerator(frac *frac)
  • GetDenominator(frac *frac)
  • GetInteger(frac *frac)

conversion functions

  • FloatToFrac(value float64)
  • FracToFloat(frac *frac)

formatting functions

  • FormatFracOnly(frac *frac)
  • FormatSimplify(frac *frac)

operations

  • 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)

About

Go library that adds fraction-like capabilities to Go.

License:MIT License


Languages

Language:Go 100.0%