BigDecimal
The BigDecimal package provides arbitrary-precision (with an adjustable upper limit for performance) and fixed-precision decimal arithmetic in Swift.
It is available from GitHub here.
Its functionality falls in the following categories:
- Arithmetic: addition, subtraction, multiplication, division, remainder and exponentiation
- Constants: pi, zero, one, ten
- Functions: exp, log, log10, log2, pow, sqrt, root, factorial, gamma, trig + inverse, hyperbolic + inverse
- Rounding and scaling according to one of the rounding modes:
- awayFromZero
- down
- towardZero
- toNearestOrEven
- toNearestOrAwayFromZero
- up
- Comparison: the six standard operators
==
,!=
,<
,<=
,>
, and>=
- Conversion: to String, to Double, to Decimal (the Swift Foundation type), to Decimal32 / Decimal64 / Decimal128
- Support for Decimal32, Decimal64 and Decimal128 values stored as UInt32, UInt64 and UInt128 values respectively, using Densely Packed Decimal (DPD) encoding or Binary Integer Decimal (BID) encoding
- Support for Decimal32, Decimal64 and Decimal128 mathematical operations
- Supports the IEEE 754 concepts of Infinity and NaN (Not a Number) with the latter having a
signaling
option.
For more details please see Big Decimal