Arbitrary precision decimal arithmetic library for Elixir, representing numbers exactly with sign, coefficient, and exponent.
Decimal is an Elixir library for arbitrary precision decimal arithmetic, enabling exact representation of numbers of any size and decimal places. It solves floating-point inaccuracies by using a three-integer internal representation (sign, coefficient, exponent), making it essential for financial, scientific, and other precision-sensitive calculations.
Elixir developers working on applications requiring exact decimal calculations, such as financial systems, scientific computations, or any domain where rounding errors are unacceptable.
Developers choose Decimal for its exact representation of decimals, configurable precision and rounding via a context system, and adherence to decimal arithmetic standards, ensuring reliable and predictable results without floating-point errors.
Arbitrary precision decimal arithmetic
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses a three-integer internal model (sign, coefficient, exponent) to represent numbers exactly, eliminating floating-point rounding errors as demonstrated in the concept examples.
Allows setting maximum decimal digits via the context system, enabling precise control over calculation results, shown in the precision and rounding examples.
Supports multiple rounding methods like :half_up and :floor, which can be set in the context to tailor rounding behavior for specific needs.
Includes flags and trap enablers to signal and optionally raise errors for conditions like division_by_zero, enhancing reliability in error-prone calculations.
Stores configuration in the process dictionary, which complicates concurrent usage and requires careful management in multi-process environments.
Arbitrary precision calculations are inherently slower than native floating-point operations, making it unsuitable for high-performance numerical tasks.
Requires using specific functions like Decimal.compare/2 instead of standard operators, increasing code verbosity and potential for misuse.
The README has incomplete sections, such as the 'TODO' on mitigating rounding errors, which may leave users without full guidance on advanced topics.