Skip to content

Provides basic arithmetic functions in go without the need for type conversion

License

Notifications You must be signed in to change notification settings

NdoleStudio/arithmetic

Repository files navigation

arithmetic

Build Status codecov Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides basic arithmetic functions without the need for type casting when working with go.

Install

go get https://github.com/NdoleStudio/arithmetic

Or

import "github.com/NdoleStudio/arithmetic"

Benchmarks

This is a benchmark for computing the same functions using this library and doing it natively using type casting. I'm running this tests on a late 2018 a Macbook Pro with 16 GB RAM and a 2.3 GHz Quad-Core Intel Core i5 processor.

DivideIntsReturnFloat

DivideIntsReturnFloat(1, 3)
// vs
float63(1) / float64(3)
BenchmarkDivideIntsReturnFloat-8                 1000000000               0.572 ns/op
BenchmarkDivideIntsReturnFloatNative-8           1000000000               0.553 ns/op

MinInt

MinInt(31, 42)
// vs
Math.Min(float63(31), 42)
BenchmarkMinInt-8                                1000000000               0.545 ns/op
BenchmarkMathMin-8                               437190435                2.75 ns/op

MinInts

MinInts(42,90, 30)
BenchmarkMinInts-8                               256053702                4.82 ns/op

MaxInt

MaxInt(31, 42)
// vs
Math.Max(float63(31), 42)
BenchmarkMaxInt-8                                1000000000               0.576 ns/op
BenchmarkMathMax-8                               404535982                2.93 ns/op

MaxInts

MaxInts(42,90, 30)
BenchmarkMaxInts-8                               275597671                4.32 ns/op

About

Provides basic arithmetic functions in go without the need for type conversion

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages