modulepackage
0.0.0-20200903114555-f7e6cb295f76
Repository: https://github.com/ndolestudio/arithmetic.git
Documentation: pkg.go.dev
# README
arithmetic
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
# Functions
DivideIntsReturnFloat divides 2 integers and returns a float64 as output.
MaxInt returns the maximum of 2 integers.
MaxInts returns the maximum of the input integers.
MinInt returns the minimum of 2 integers.
MinInts returns the minimum of the input integers.