Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jessealama/decimal128
JavaScript userland partial implementation of IEEE 754 Decimal128 decimal floating-point arithmetic
https://github.com/jessealama/decimal128
Last synced: 4 days ago
JSON representation
JavaScript userland partial implementation of IEEE 754 Decimal128 decimal floating-point arithmetic
- Host: GitHub
- URL: https://github.com/jessealama/decimal128
- Owner: jessealama
- License: bsd-2-clause
- Created: 2023-04-26T07:53:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-30T10:30:33.000Z (7 months ago)
- Last Synced: 2024-05-01T22:56:33.974Z (7 months ago)
- Language: JavaScript
- Size: 1.52 MB
- Stars: 6
- Watchers: 3
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# decimal128.js—A userland approximation to IEEE 754 Decimal128 in JavaScript
This library is a prototype for the [decimal proposal](https://github.com/tc39/proposal-decimal). There should be no observable difference between what this library does and what the proposal is [supposed to do](http://tc39.es/proposal-decimal/). If you find a mismatch, please file [an issue](https://github.com/jessealama/decimal128/issues) in this repo.
## Operations
- absolute value (`abs`)
- addition (`add`)
- subtraction (`subtract`)
- multiplication (`multiply`)
- division (`divide`)
- remainder (`remainder`)
- rounding (`round`)
- `toString` emitting both decimal and exponential syntax (default is decimal)## Comparisons
- equality (`equals`) to compare for mathematical equality
- less than (`lessThan`) to compare mathematical order
- `compare` for comparing Decimals as digit strings (not mathematical order; e.g. `1.2` < `1.20`)## Implementation
This package is written in TypeScript. Unit tests are in Jest. There are no other external dependencies.
## Data model
This package aims to reproduce the IEEE 754 [Decimal128](https://en.wikipedia.org/wiki/Decimal128_floating-point_format) 128-bit decimal floating-point numbers in JavaScript. See the [decimal proposal](https://github.com/tc39/proposal-decimal/). These **decimal** (not binary!) numbers take up 128 bits per number. This format allows for an exact representation of decimal numbers with 34 (decimal) significant digits and an exponent between -6143 and 6144. That's a _vast_ amount of range and precision!