Coder Social home page Coder Social logo

decimal's Introduction

decimal package (go)

Package provides Decimal type which is used in various parts of finex.

Overview

Decimal type:

  • stores value in single uint64;
  • is unsigned;
  • has minimum value of 0.00000000;
  • has maximum value of 99999999999.99999999;
  • is equivalent to MySQL type DECIMAL(19, 8) UNSIGNED;
  • can be added (+), subtracted (-) and compared (>, <, ==) directly;
  • can be multiplied using Multiply() method;
  • can store 1 satoshi (BTC) or 10 Gwei (ETH) without losing precision: 0.00000001

Design

Max uint64 value is 18446744073709551615, which has string length of 20 characters, so we can reliably represent decimal number with 19 decimal points in total:

18446744073709551615
_9999999999999999999
99999999999.99999999
||||||||||| 100000000 = 1e8
100000000000          = 1e11

Benchmarks

BenchmarkDecimal_Scan-4                 10000000             156    ns/op
BenchmarkDecimal_String-4               20000000              76.4  ns/op
BenchmarkDecimal_Split-4              2000000000               0.58 ns/op
BenchmarkDecimal_Multiplication-4        5000000             253    ns/op

PASS
ok      github.com/openware/decimal     6.212s

decimal's People

Contributors

seletskiy avatar kovetskiy avatar

Watchers

James Cloos avatar Marlon Hanks avatar

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.