Giter Site home page Giter Site logo

bigint's Introduction

bigint

Go's big.Int is mutable to enable flexibility in performance tuning but sometimes immutability is more desired. To write immutable code with big.Int we need to be really verbose like new(big.Int).Add(a, b). This package provides an immutable wrapper around big.Int. Other than the immutability, it tries to be as similar to big.Int as possible. Examples:

int big.Int bigint
42 big.NewInt(42) bigint.New(42)
strconv.Atoi("123") new(big.Int).SetString("123", 10) bigint.FromString("123", 10)
a := b a := new(big.Int).Set(b) a := b
a := b + c a := new(big.Int).Add(b, c) a := b.Add(c)
a += b a.Add(a, b) a = a.Add(b)
a + b * c new(big.Int).Add(a, new(big.Int).Mul(b, c)) a.Add(b.Mul(c))
(a + b) * c new(big.Int).Mul(new(big.Int).Add(a, b), c) a.Add(b).Mul(c)
a == b a.Cmp(b) == 0 a.EQ(b)
a < b a.Cmp(b) < 0 a.LT(b)

Check documentation for all utility functions: to be updated...

Install

go get github.com/minswap/bigint

Roadmap

  • Support all functions from big.Int
  • 100% test coverage

bigint's People

Contributors

longngn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

beerhouse-io

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.