break-infinity.rs (extended)
This is a fork of https://github.com/Redfire75369/break-infinity.rs; it includes refactorings and a few extensions and optimizations.
A port of Patashu's break_infinity.js to Rust.
It provides the Decimal
number struct which is able to reach a maximum value of 1e1.79e308
(1*101.79*10308
) instead of f64
's maximum of 1.79e308
(1.79*10308
).
The exponent lies between Uncentillion (10306
) and Duocentillion (10309
), already an incredibly large number.
To write the final number, you would to have to write a 1
followed by (almost) 1.79 * 10308 zeroes.
The biggest/smallest value (which does not parse into Infinity) with completely written out exponent is:
10±178999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Yep, that's a lot of digits.
It only needs two f64
s internally, in other words: 128 bits (16 bytes) total in memory.
Installation
You can install this package via Cargo by adding these lines to your Cargo.toml
:
[dependencies]
break_infinity_extended = { git = "https://github.com/asaaki/break-infinity.rs" }
Features
serde
: if you need to (de)serialize the values (useful for saving or transport)compat
: enables break_infinity transformation functions; only useful when you transition between crates
Usage
This library allows simple creation of Decimal
's through many different methods.
use break_infinity_extended as bie;
fn main() {
let x = bie::Decimal::new(123.456);
let y = bie::Decimal::from(123i32);
let z = bie::from_mantissa_exponent(1.23, 9.0);
let s = bie::Decimal::from("78.90");
}
Methods that return a Decimal
can also be chained:
use break_infinity_extended as bie;
fn main() {
let chained = x.abs().ceil().exp().log10();
}
Acknowledgements
- Redfire75369 for creating the Rust implementation, which this is a fork of.
- Patashu and Razenpok for creating the original
break_infinity.js
that the original Rust version is based off of.