Skip to content

Crypt0plasm/Firefly-APD

Repository files navigation

Firefly-APD

Firefly-APD is an ArbitraryPrecisionDecimal Library forked from cockroachdb/apd Library.

go get github.com/Crypt0plasm/Firefly-APD

Similar to cockroachdb/apd, Firefly-APD implements much of the decimal specification from the General Decimal Arithmetic description. This is the same specification implemented by python’s decimal module and GCC’s decimal extension.

Main Features

  • 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.
  • Support for standard functions. sqrt, ln, pow, etc.
  • 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.
  • 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.
  • Condition flags and traps. All operations will report whether their result is exact, is rounded, is over- or under-flowed, is subnormal, 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.

Secondary Features

  • Added SIN function support
  • Added a triangle solve Function ASA, angle,side,angle variant, with more to be added as needed.

Firefly-APD has two main types:

The first is Decimal which holds the values of decimals. It is simple and uses a big.Int with an exponent to describe values. Most operations on Decimals can’t produce errors as they work directly on the underlying big.Int. Notably, however, there are no arithmetic operations on Decimals.

The second main type is 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.

Documentation

similar to cockroachdb/apd:

https://pkg.go.dev/github.com/cockroachdb/apd/v2?tab=doc

About

Firefly Arbitrary Precision Decimal Package

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages