• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

testdata/H08-Apr-2019-27,17625,873

.travis.ymlH A D08-Apr-201956 85

LICENSEH A D08-Apr-201911 KiB203169

README.mdH A D08-Apr-20192.9 KiB2515

bench_test.goH A D08-Apr-20192.8 KiB10676

condition.goH A D08-Apr-20195.3 KiB16794

const.goH A D08-Apr-20199 KiB12380

const_test.goH A D08-Apr-20191.1 KiB3518

context.goH A D08-Apr-201932.4 KiB1,283883

decimal.goH A D08-Apr-201919.7 KiB836571

decimal_test.goH A D08-Apr-201916.7 KiB840778

doc.goH A D08-Apr-20193.2 KiB751

error.goH A D08-Apr-20195 KiB189119

error_test.goH A D08-Apr-20191.4 KiB5432

example_test.goH A D08-Apr-20194 KiB13581

form_string.goH A D08-Apr-2019355 1710

format.goH A D08-Apr-20195.3 KiB209146

gda_test.goH A D08-Apr-201920.5 KiB908799

go.modH A D08-Apr-201975 42

go.sumH A D08-Apr-2019161 32

loop.goH A D08-Apr-20192.9 KiB9052

round.goH A D08-Apr-20194.9 KiB193131

sql_test.goH A D08-Apr-20192 KiB7855

table.goH A D08-Apr-20193.8 KiB13984

table_test.goH A D08-Apr-20194 KiB168135

README.md

1# apd
2
3apd is an arbitrary-precision decimal package for Go.
4
5`apd` implements much of the decimal specification from the [General Decimal Arithmetic](http://speleotrove.com/decimal/) description. This is the same specification implemented by [python’s decimal module](https://docs.python.org/2/library/decimal.html) and GCC’s decimal extension.
6
7## Features
8
9- **Panic-free operation**. The `math/big` types don’t return errors, and instead panic under some conditions that are documented. This requires users to validate the inputs before using them. Meanwhile, we’d like our decimal operations to have more failure modes and more input requirements than the `math/big` types, so using that API would be difficult. `apd` instead returns errors when needed.
10- **Support for standard functions**. `sqrt`, `ln`, `pow`, etc.
11- **Accurate and configurable precision**. Operations will use enough internal precision to produce a correct result at the requested precision. Precision is set by a "context" structure that accompanies the function arguments, as discussed in the next section.
12- **Good performance**. Operations will either be fast enough or will produce an error if they will be slow. This prevents edge-case operations from consuming lots of CPU or memory.
13- **Condition flags and traps**. All operations will report whether their result is exact, is rounded, is over- or under-flowed, is [subnormal](https://en.wikipedia.org/wiki/Denormal_number), or is some other condition. `apd` supports traps which will trigger an error on any of these conditions. This makes it possible to guarantee exactness in computations, if needed.
14
15`apd` has two main types. The first is [`Decimal`](https://godoc.org/github.com/cockroachdb/apd#Decimal) which holds the values of decimals. It is simple and uses a `big.Int` with an exponent to describe values. Most operations on `Decimal`s can’t produce errors as they work directly on the underlying `big.Int`. Notably, however, there are no arithmetic operations on `Decimal`s.
16
17The second main type is [`Context`](https://godoc.org/github.com/cockroachdb/apd#Context), which is where all arithmetic operations are defined. A `Context` describes the precision, range, and some other restrictions during operations. These operations can all produce failures, and so return errors.
18
19`Context` operations, in addition to errors, return a [`Condition`](https://godoc.org/github.com/cockroachdb/apd#Condition), which is a bitfield of flags that occurred during an operation. These include overflow, underflow, inexact, rounded, and others. The `Traps` field of a `Context` can be set which will produce an error if the corresponding flag occurs. An example of this is given below.
20
21See the [examples](https://godoc.org/github.com/cockroachdb/apd#pkg-examples) for some operations that were previously difficult to perform in Go.
22
23## Documentation
24
25https://godoc.org/github.com/cockroachdb/apd