Skip to content
Fixed-precision decimal numbers based on IEEE 754 decimal64
Go
Branch: master
Clone or download
Joshcarp Support 32 bit architectures
Makes troublesome consts uint64's to stop integer overflow from implicit typecasting into 32 bit integers in 32 bit systems.
Latest commit ed1ea41 Nov 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dectest
.gitignore
.travis.yml
LICENSE Add apache 2 license (#65) Oct 31, 2019
README.md
decimal64.go
decimal64_test.go Support 32 bit architectures Nov 15, 2019
decimal64const.go Support 32 bit architectures Nov 15, 2019
decimal64const_test.go
decimal64decParts.go
decimal64decParts_test.go
decimal64fmt.go Clean up error messages and shadowed types/vars (#63) Sep 4, 2019
decimal64fmt_test.go
decimal64gob.go Refactor into functionality-specific files Oct 27, 2018
decimal64gob_test.go Replace "Decimal64" with just "64" (#67) Nov 14, 2019
decimal64json.go
decimal64json_test.go
decimal64marshal.go Replace "Decimal64" with just "64" (#67) Nov 14, 2019
decimal64marshal_test.go
decimal64math.go
decimal64math_test.go
decimal64scan.go
decimal64scan_test.go
decimalSuite_test.go
flakyScanState_test.go
go.mod
go.sum
logic.go
logic_test.go Refactor tests Oct 27, 2018
stringScanner.go
stringScanner_test.go Remove unused wid from stringScanner Nov 4, 2018
uint128.go
uint128_test.go Support 32 bit architectures Nov 15, 2019
util_test.go

README.md

⛔️ NOTICE: USE OF THIS LIBRARY IN ANZ SYSTEMS IS STRICTLY PROHIBITED. ⛔️
This library is currently in development and has not undergone a thorough correctness assessment or security audit. It is therefore NOT suitable for production use until full approval is granted by the ANZ open source committee and this notice removed.

decimal

This library implements fixed-precision decimal numbers based on IEEE 754R standard; https://ieeexplore.ieee.org/document/4674342 More info can be found at: http://speleotrove.com/decimal/

Features

  • Decimal64, partial implementation of the ieee-754R standard
  • Half up and half even rounding
  • Up to 3 times faster than arbitrary precision decimal libraries in Go

Goals

  • To implement 128 bit decimal

Installation and use

Run go get github.com/anz-bank/decimal

package main

import (
	"fmt"

	"github.com/anz-bank/decimal"
)

func main() {
	var a decimal.Decimal64
	b := decimal.MustParse64("0.1")
	c := decimal.MustParse64("0.3")
	d := decimal.New64FromInt64(123456)

	fmt.Println(a, b, c, d)
}

Docs

https://godoc.org/github.com/anz-bank/decimal

Why decimal

Binary floating point numbers are fundamentally flawed when it comes to representing exact numbers in a decimal world. Just like 1/3 can't be represented in base 10 (it evaluates to 0.3333333333 repeating), 1/10 can't be represented in binary. The solution is to use a decimal floating point number. Binary floating point numbers (often just called floating point numbers) are usually in the form Sign * Significand * 2 ^ exp and decimal floating point numbers change this to Sign * Significand * 10 ^ exp This eliminates the decimal fraction problem, as the base is in 10.

Why fixed precision

Most implementations of a decimal floating point datatype implement an 'arbitrary precision' type, which often uses an underlying big int. This gives flexibility in that as the number grows, the number of bits assigned to the number grows ( and thus 'arbitrary precision'). This library is different as it specifies a 64 bit decimal datatype as specified in the ieee-754R standard. This gives the sacrifice of being able to represent arbitrarily large numbers, but is faster than other arbitrary precision libraries.

You can’t perform that action at this time.