NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #907 most downloaded on crates.io
Lossless fractions and decimals; drop-in float replacement
Last release 1 months ago
22 Aug 2026
Ships unpredictably
gaps range from 2 weeks to 1.9 years
Nearly every release is documented
notes for 38 of 38 stable releases
1 version withdrawn
withdrawn after publishing
11 years old
39 releases · first in 2016
Breaking: GenericFraction::<T>::from_unicode_str now requires T: CheckedAdd + CheckedMul . Custom backing types must provide both operations for mixed
GenericFraction::<T>::from_unicode_str now requires T: CheckedAdd + CheckedMul. CustomFraction/Decimal, Unicode, GenericFraction radix, andDecimal grammar.From<&str> for GenericDecimal continues to map parse failures to NaN.GenericFraction changes its Num::FromStrRadixErr associated type from ParseRatioError toParseError. Its fraction-only numerator/denominator grammar is unchanged, zero denominators returnParseError::ZeroDenominator, and direct Ratio parsing still uses ParseRatioError.ParseError is now non-exhaustive; downstream matches must include a wildcard arm.DynaInt changes its Num::FromStrRadixErr associated type to ParseError; malformed inputs andParseError::ParseIntError.ParseIntError when the raw combined numeratorwhole × denominator + numerator) is not representable by the backing integer type, instead of panicking inGenericFraction and DynaInt radix parsing no longer panic for bases outside 2 through 36; they returnParseError::UnsupportedBase instead of forwarding invalid bases to their backing integer implementations.One column per quarter.
Replaced optional lazy_static usage with std::OnceLock and num-bigint constants for approximation accuracy multipliers (special thanks to Expyron for
lazy_static usage with std::sync::OnceLock and num-bigint constants for approximation accuracy multipliers (special thanks to Expyron for the std::sync::OnceLock patch).from_unicode_str) rather than panicking.Ord/PartialOrd/Eq/Hash consistency by comparing each value using its stored precision, including truncation and canonical zero handling (-0, -0.9@p0, -0.04@p1), so ordered and hashed collections now agree.NUMERIC infinity round-trip support for both Fraction and Decimal, encoding/decoding ±Infinity using 0xD000/0xF000 markers and documenting PostgreSQL 14+/unconstrained NUMERIC requirements.Remove deprecations & fix lints by @dnsl48 in #111
from_fraction_with_precision helperCargo.toml as edition = "2015".num crate min required version is now 0.4.3cargo test no longer fails without with-unicode.num crate min required version is now 0.4.2 (The one where ConstOne and ConstZero were introduced)
num crate min required version is now 0.4.2 (The one where ConstOne and ConstZero were introduced)GenericFraction ConstOne and ConstZero trait implementations (special thanks to Raimundo Saona, aka @saona-raimundo )
"with-unicode" feature implementation to format (and parse) floats with Unicode characters (special thanks to @feefladder )
GenericFraction try_from/try_into implementations for primitive types (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize, f32, f64)
sub_assign and checked_sub that could sometimes produce incorrect results for a couple of edge cases with a negative zero (-0) as an operand.approx module with "Approximate mathematical operations", fn sqrt (special thanks to @squ1dd13 for the contribution!)
approx module with "Approximate mathematical operations", fn sqrt (special thanks to @squ1dd13 for the contribution!)with-approx feature, enabling the approx moduleClippy hint to allow manual filtering in GenericFraction::to_i64 implementation
PartialCmp now compares NaN with the other values and returns it as the smallest possible value. Thus, NaN < -Inf .
PartialCmp now compares NaN with the other values and returns it as the smallest possible value. Thus, NaN < -Inf.partial_cmp now behaves exactly the same as cmp (PartialOrd is now consistent with Ord).0.12.2 with the implementation of Ord,Ord would behave differently from PartialOrd with NaN values.Ord trait implementation for GenericFraction and GenericDecimal (special thanks to Hsingai Tigris Altaica aka DrAlta)
Ord trait implementation for GenericFraction and GenericDecimal (special thanks to Hsingai Tigris Altaica aka DrAlta)Support to add castable values (e.g. f + 1u8, 1u8 will be transparently casted to Fraction with .into())
add castable values (e.g. f + 1u8, 1u8 will be transparently casted to Fraction with .into())sub castable values (e.g. f - 1u8, 1u8 will be transparently casted to Fraction with .into())div castable values (e.g. f / 1u8, 1u8 will be transparently casted to Fraction with .into())mul castable values (e.g. f * 1u8, 1u8 will be transparently casted to Fraction with .into())add_assign castable values (e.g. f += 1u8, 1u8 will be transparently casted to Fraction with .into())sub_assign castable values (e.g. f -= 1u8, 1u8 will be transparently casted to Fraction with .into())div_assign castable values (e.g. f /= 1u8, 1u8 will be transparently casted to Fraction with .into())mul_assign castable values (e.g. f *= 1u8, 1u8 will be transparently casted to Fraction with .into())fn decimal::GenericDecimal::apply_ref is deprecated.
num version 0.4 is now required (0.2, 0.3 are no longer supported)decimal::GenericDecimal::apply_ref is deprecated.decimal::GenericDecimal::from_decimal_str. Use FromStr::from_str instead.fraction::GenericFraction::from_decimal_str. Use FromStr::from_str instead.fraction::GenericFraction::format_as_decimal. Use format!(\"{:.1$}\", fraction, precision) instead.fraction::GenericFraction::new_raw_neg. Use new_raw_signed instead.DynaInt now implements serde Serialize & Unserialize (Thanks to Richard Davies aka @optevo for the contribution!)
DynaInt now implements serde Serialize & Unserialize (Thanks to Richard Davies aka @optevo for the contribution!)Fraction::from\_str trims trailing zeroes before calculating denom (Thanks to @khigia for the contribution!)
num dependency versions extended from 0.2 to >=0.2,<5 (Thanks to Joel Natividad aka jqnatividad for the contribution!)
num dependency versions extended from 0.2 to >=0.2,<5 (Thanks to Joel Natividad aka jqnatividad for the contribution!)lazy_static dependency versions extended from 1.1 to 1Deprecated GenericFraction::from_decimal_str and GenericDecimal::from_decimal_str in favour of of std::FromStr
std::str::FromStr trait implementation for GenericFraction and GenericDecimal
Special thanks to Scott Wilson for the contributionGenericFraction::from_decimal_str and GenericDecimal::from_decimal_str in favour of of std::str::FromStrDeprecated fn GenericFraction::format_as_decimal is removed
postgres-types: ^0.2 and bytes: 1 are new optional dependencies (feature: with-postgres-support)GenericFraction::new_raw_signed constructorpostgres crate is not a dependency any longerGenericFraction::format_as_decimal is removedMore efficient f32/f64 conversion to Fractions and Decimals (up to 10 times faster and not using memory allocation anymore) Special thanks to Christop
fraction::Format implements Clone trait (becomes cloneable)
std::{Sum, Product} implemented for GenericFraction and GenericDecimal
std::Error implemented for error::ParseError
fraction, GenericFraction::into_fraction method implementation
Into<BigUint> implementationGenericFraction::into_fraction<I> method implementationGenericFraction::format_as_decimal is now deprecated. Use format! macro instead, or division module if you need more control
Division module API; functions to return division state for later reuse (remainder and divisor)
DynaInt, initial std::Display implementation
DynaInt, initial std::fmt::Display implementationGenericFraction redundant methods deprecated: new_nan, new_inf, new_inf_neg, into_big, format_as_float
Hash implementation for GenericFraction now returns equal hashes for negative and positive zeroesnum traits so that the library can be used without explicit dependency on numconvert module with traits for optimistic convesiondecimal module with GenericDecimal implementation, Juniper and PostgreSQL integration for itdivision module with lossless infinite division implementation without memory allocationdynaint module with DynaInt type implementation (dynamically growing integer)error module with shared library error typesfraction module with GenericFraction implementation, Juniper and PostgreSQL integration for itgeneric module with GenericInteger trait implementation, generic integer types conversionprelude module with some predefined type aliases such as Fraction and Decimaltests module with some testswith-bigint (default), integration with num::{BigInt, BigUint} typeswith-decimal (default), GenericDecimal type implementationwith-dynaint (default), DynaInt type implementationwith-juniper-support, Juniper 0.10 integrationwith-postgres-support, Postgres 0.15 integrationGenericFraction redundant methods deprecated: new_nan, new_inf, new_inf_neg, into_big, format_as_floatFix comparisons with negative numbers
T in GenericFraction is Clone + Integer from now onwards (thanks to Taryn Hill aka Phrohdoh)
T in GenericFraction<T> is Clone + Integer from now onwards (thanks to Taryn Hill aka Phrohdoh)num package dependency version updated from "0.1.36" to "0.1.37"
num package dependency version updated from "0.1.36" to "0.1.37"fn _new now returns NaN for 0/0 (was Infinity before)
fn _new now returns NaN for 0/0 (was Infinity before)fn sign now returns values for GenericFraction::Infinite values toofn neg_zero now returns zero with negative sign (was positive before)fn recip now handles zero values gracefully (does not panic, returns Infinity)More efficient implementation of From<[unsigned ints]>
From<[unsigned ints]>From<BigInt>Zero::is_zero to be used everywhere in math, rather than making new zero vals + comparing with them
Zero::is_zero to be used everywhere in math, rather than making new zero vals + comparing with themfn new_nan constructorfn new_inf constructorfn new_inf_neg constructorfn format_as_float implemented for GenericFraction (it was only available for BigFraction before)
fn format_as_float implemented for GenericFraction<T> (it was only available for BigFraction before)Into<T> to be used in bounds rather than From<N>, since it's more flexible (thanks to Alexander Altman for the patch)fn format_as_float + test coverageFrom<(N, D)> generic implementation (through std::Display)
From<(N, D)> generic implementation (through std::fmt::Display)GenericFraction<T> copy semantic to be applied only when T: CloneGenericFraction impl, constructors refactoring (new, new_raw)num upgraded up to 0.1.36 (from 0.1.34)fn new does not perform type casting through fmt::Display anymore (that functionality moved out as From<(N, D)>)### Added - impl From for BigFraction - impl From for BigFraction
impl From<num::BigInt> for BigFractionimpl From<num::BigUint> for BigFractionPackage description has been changed
GenericFraction implemented upon num::Ratio
GenericFraction<T> implemented upon num::Ratio<T>BigFraction implementation based on num::BigRational (using heap)num::traits::Bounded trait implementedfn min_positive_value implementednum::traits::ToPrimitive trait implementednum::traits::Signed trait implementedFrom<f64> trait implementation now relies on format! macro instead of f64::fractBigFraction struct using num::BigUintfn format_as_float for BigFraction has been implementedLGPL-3 to MIT/Apache2 dualfn to_f64 now returns Option<f64> instead of f64 (num::trait::ToPrimitive implementation)From trait implementation uses fmt::Display from now onfn unpack removedstd::cmp::Ord implementation removed in regard to NaN values### Added - Basic implementation
Your coding agent can read these notes before it upgrades. Set up the MCP server →