compa_decimal
A compact and efficient decimal system using a custom character set for representing large numbers in fewer characters.
Features
- Custom Character Set: Uses numbers, uppercase and lowercase letters, and special characters for a base-95 numeral system.
- Supports Multiple Numeric Types: Easily convert between unsigned integers (
u8,u16,u32,u64,u128) and theCompaDecimalformat. - Conversion Utilities: Convert between standard decimal numbers and the compact
CompaDecimalrepresentation. - Extensible: Designed for future support of arbitrarily large numbers.
Usage
Add to your Cargo.toml:
[]
= "0.1.0"
Import in your Rust code:
use CompaDecimal;
Examples
Creating a New CompaDecimal
let compa = new;
assert_eq!;
Parsing from &str
let compa: CompaDecimal = "123asd".parse.unwrap;
assert_eq!;
Decimal to CompaDecimal
let compa = .unwrap;
assert_eq!;
Get Value
let compa = "1LY7VK"..unwrap;
let compa_value = compa.get_value;
assert_eq!;
Increment and Decrement
let compa = "A1"..unwrap;
let increased = compa.plus_one.unwrap;
assert_eq!;
let decreased = increased.minus_one.unwrap;
assert_eq!;
Add and Subtract
let compa = "ASr35"..unwrap;
let new_compa = compa.add.unwrap;
assert_eq!;
let subtracted = new_compa.subtract.unwrap;
assert_eq!;
Compare
use Ordering;
let compa = "axswF9"..unwrap;
assert_eq!;
Length
let compa = "1LY7VK"..unwrap;
assert_eq!;
Convert Back to Decimal
let compa = "1LY7VK"..unwrap;
let decimal: u64 = compa.to_decimal.unwrap;
assert_eq!;
Error Handling
Most methods return a Result and will return an error if:
- The input contains invalid characters.
- The operation would result in a negative value.
- The value is too large for the target integer type.
License
Licensed under MIT OR Apache-2.0.