Coder Social home page Coder Social logo

fractions's Introduction

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.