Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mongodb-rust/decimal128

WASM-compatible Decimal128 implementation
https://github.com/mongodb-rust/decimal128

Last synced: about 2 months ago
JSON representation

WASM-compatible Decimal128 implementation

Awesome Lists containing this project

README

        

decimal 128




128-bit wide floating point implementation for Rust





Crates.io version



Download



docs.rs docs

## Installation
```shell
cargo add decimal128
```

## Usage
This crate is a work-in-progress and does not have all applicable methods implemented as per [IEEE Standard for Floating-Point Arithmetic](https://ieeexplore.ieee.org/document/4610935) and [MongoDB Decimal128 BSON type](https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst). The following methods are currently implemented:
- `Decimal128.from_raw_bytes`
- `Decimal128.zero`
- `Decimal128.is_nan`
- `Decimal128.is_negative`
- `Decimal128.is_zero`
- `Decimal128.to_string`

```rust
use decimal128;

let vec: [u8; 16] = [
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
];
let dec128 = Decimal128::from_raw_buf(vec);
let string = dec128.to_string();
assert_eq!("-Infinity".to_string(), string);
```

## License

Licensed under the Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
at your option.