Skip to content
/ decnum0 Public

old decnum package. It works very well, but the API is not that good.

Notifications You must be signed in to change notification settings

rin01/decnum0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

decnum

This is a Go binding around C decNumber package, for calculation with base-10 floating point numbers. Decimal data type is important for financial calculations.

The C decNumber package can be found at: http://speleotrove.com/decimal/

I downloaded the decNumber package "International Components for Unicode (ICU)".

WARNING: don't use this package. The API is being completely reworked.

Documentation of original C decNumber package

Its documentation is here: http://speleotrove.com/decimal/decnumber.html

More specifically, you should read these topics:

The original C decNumber package contains two kinds of data type:

  • decNumber, which contains arbitrary-precision numbers. Storage will grow as needed.
  • decQuad, decDouble, decSingle, which are fixed-size data types. They are faster than decNumber.

This Go package

This Go package only uses the decQuad data type, which is 128 bits long. It can store numbers with 34 significant digits. It is very much like the float64, except that its precision is better (float64 has a precision of only 15 digits), and it works in base-10 instead of base-2.

I have only written the following files:

The other .c and .h files in the directory come from the original C decNumber package.

The code of this Go wrapper is quite easy to read, and the pattern for calling C function is always the same. Parameters are always passed from Go to C as value, and in the other direction too. Strings passed from C to Go are are also passed by value, as array in struct. Strings passed from Go to C using C.CString(s).

Installation:

go get github.com/rin01/decnum

Godoc

https://godoc.org/github.com/rin01/decnum

Example

You can find an example of use in the directory decnum/example_decnum.

https://github.com/rin01/decnum/blob/master/example_decnum/main.go

Test

The test file mydecquad_test.go is very instructive.

Run the test:

go test

About

old decnum package. It works very well, but the API is not that good.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages