approx_int
About
This library provides a utility for approximating large numbers by calculating the number of bits needed to store a number (similar to determining the exponent in mathematics). The algorithm determines the maximum value that can be represented using this bit length, and then finds the nearest percentage value that can approximately match the original number. This approximation reduces the size of the number, while retaining enough information for practical use.
The compact representation of numbers using a tuple (u8, u8, bool):
u8for the number of bits required to store the value.u8for the percentage that describes the degree of approximation.boolfor storing the sign of the number (true if negative).
In total, this representation uses 24 bits. The approximate number will always be lower than the original one, with the exception of only the number 0. While there is some loss of precision, this approach is useful in scenarios where exact values are not critical.
let big_value: u128 = 8838183818381831838138182391233;
let small_value: = new.into;
println!;
println!;
let small_value: = small_value.into;
println!;
---- stdout ----
The raw value: (103, 87, false)
The original value: 8838183818381831838138182391233
The approximate value: 8822848225945509419002221297664