Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/horvathandris/bigdecimal
Arbitrary precision decimal arithmetic for Gleam
https://github.com/horvathandris/bigdecimal
Last synced: about 1 month ago
JSON representation
Arbitrary precision decimal arithmetic for Gleam
- Host: GitHub
- URL: https://github.com/horvathandris/bigdecimal
- Owner: horvathandris
- License: apache-2.0
- Created: 2024-10-05T11:37:36.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-23T08:33:49.000Z (about 2 months ago)
- Last Synced: 2024-10-23T11:36:59.374Z (about 2 months ago)
- Language: Gleam
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-gleam - bigdecimal - [📚](https://hexdocs.pm/bigdecimal/) - Arbitrary precision decimal arithmetic for Gleam (Packages / Numbers)
README
# :b: bigdecimal
[![Package Version](https://img.shields.io/hexpm/v/bigdecimal)](https://hex.pm/packages/bigdecimal)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/bigdecimal/)
![Erlang Target](https://img.shields.io/badge/target-erlang-A90433)
![JavaScript Target](https://img.shields.io/badge/target-javascript-F7E02A)A library for [arbitrary precision decimal arithmetic](https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic) in Gleam.
This library builds on the excellent [bigi](https://hex.pm/packages/bigi) library.
A `BigDecimal` consists of an arbitrary precision integer unscaled value of type `bigi.Bigint`
and an integer scale of built-in type `Int` (arbitrary precision on the Erlang target, bound between
[Number.MIN_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
and [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
on the JavaScript target). If zero or positive, the scale is the number of digits to the right of
the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power
of the negation of the scale. The value of the number represented by the `BigDecimal` is therefore
unscaled_value × 10-scale.## Usage
```sh
gleam add bigdecimal@1
``````gleam
import bigdecimalpub fn main() {
let assert Ok(number) = bigdecimal.from_string("12.00340")bigdecimal.scale(of: number) // 5
bigdecimal.unscaled_value(of: number) // 1_200_340
}
```Further documentation can be found at .
## Development
The library supports all targets and runtimes. To do a matrix run of the test suite, run:
```sh
./scripts/matrix-test.sh
```## TODO
- [ ] remainder
- [ ] square root