Crate bigfloppa

Source
Expand description

A Big Decimal

BigDecimal allows storing any real number to arbitrary precision; which avoids common floating point errors (such as 0.1 + 0.2 ≠ 0.3) at the cost of complexity.

Internally, BigDecimal uses a BigInt object, paired with a 64-bit integer which determines the position of the decimal point. Therefore, the precision is not actually arbitrary, but limited to 263 decimal places.

Common numerical operations are overloaded, so we can treat them the same way we treat other numbers.

It is not recommended to convert a floating point number to a decimal directly, as the floating point representation may be unexpected.

§Example

use bigfloppa::BigDecimal;
use std::str::FromStr;

let input = "0.8";
let dec = BigDecimal::from_str(&input).unwrap();
let float = f32::from_str(&input).unwrap();

println!("Input ({}) with 10 decimals: {} vs {})", input, dec, float);

Structs§

BigDecimal
A big decimal type.
BigInt
A big signed integer type.
ParseBigIntError

Enums§

ParseBigDecimalError
Sign
A Sign is a BigInt’s composing element.

Traits§

FromPrimitive
A generic trait for converting a number to a value.
Num
The base trait for numeric types, covering 0 and 1 values, comparisons, basic numeric operations, and string conversion.
One
Defines a multiplicative identity element for Self.
Signed
Useful functions for signed numbers (i.e. numbers that can be negative).
ToBigInt
A generic trait for converting a value to a BigInt. This may return None when converting from f32 or f64, and will always succeed when converting from any integer or unsigned primitive, or BigUint.
ToPrimitive
A generic trait for converting a value to a number.
Zero
Defines an additive identity element for Self.

Functions§

set_max_precision
set_max_scale