fraction
Lossless fractions and decimals; drop-in float replacement
0.17.0
80M downloads/mo
#910 most downloaded on crates.io
dnsl48/fraction
What this package is like to depend on
Last release today
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
3 releases in the last 12 months
see the full history below
Release timeline
39 releases · Jan 2016 to Aug 2026
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
Releases
latest 39-
0.17.022 Aug 2026Release notes
Open source →[0.17.0] - 2026-08-23
Changed
- Breaking:
GenericFraction::<T>::from_unicode_strnow requiresT: CheckedAdd + CheckedMul. Custom
backing types must provide both operations for mixed-component combination; standard bounded, big-integer, and
dynamic backings satisfy these bounds. - Breaking: Numeric-component forms in ordinary
Fraction/Decimal, Unicode,GenericFractionradix, and
Juniper parsing reject component-local signs while retaining one sign for the complete value. Fraction Juniper
input still requires its explicit outer sign; Decimal Juniper input delegates to ordinaryDecimalgrammar.
From<&str> for GenericDecimalcontinues to map parse failures to NaN. - Breaking:
GenericFractionchanges itsNum::FromStrRadixErrassociated type fromParseRatioErrorto
ParseError. Its fraction-onlynumerator/denominatorgrammar is unchanged, zero denominators return
ParseError::ZeroDenominator, and directRatioparsing still usesParseRatioError. - Breaking:
ParseErroris now non-exhaustive; downstream matches must include a wildcard arm. - Breaking:
DynaIntchanges itsNum::FromStrRadixErrassociated type toParseError; malformed inputs and
values that neither backing type can represent returnParseError::ParseIntError.
Fixed
- Unicode mixed-number parsing now returns
ParseIntErrorwhen the raw combined numerator
(whole × denominator + numerator) is not representable by the backing integer type, instead of panicking in
debug builds or wrapping in release builds. - Signed backing types no longer allow component-local signs to create negative magnitudes inside stored ratios;
component-local signed-minimum inputs now fail deterministically. GenericFractionandDynaIntradix parsing no longer panic for bases outside 2 through 36; they return
ParseError::UnsupportedBaseinstead of forwarding invalid bases to their backing integer implementations.
Release notes
Open source →Changed
- Breaking:
GenericFraction::<T>::from_unicode_strnow requiresT: CheckedAdd + CheckedMul. Custom backing types must provide both operations for mixed-component combination; standard bounded, big-integer, and dynamic backings satisfy these bounds. - Breaking: Numeric-component forms in ordinary
Fraction/Decimal, Unicode,GenericFractionradix, and Juniper parsing reject component-local signs while retaining one sign for the complete value. Fraction Juniper input still requires its explicit outer sign; Decimal Juniper input delegates to ordinaryDecimalgrammar.From<&str> for GenericDecimalcontinues to map parse failures to NaN. - Breaking:
GenericFractionchanges itsNum::FromStrRadixErrassociated type fromParseRatioErrortoParseError. Its fraction-onlynumerator/denominatorgrammar is unchanged, zero denominators returnParseError::ZeroDenominator, and directRatioparsing still usesParseRatioError. - Breaking:
ParseErroris now non-exhaustive; downstream matches must include a wildcard arm. - Breaking:
DynaIntchanges itsNum::FromStrRadixErrassociated type toParseError; malformed inputs and values that neither backing type can represent returnParseError::ParseIntError.
Fixed
- Unicode mixed-number parsing now returns
ParseIntErrorwhen the raw combined numerator (whole × denominator + numerator) is not representable by the backing integer type, instead of panicking in debug builds or wrapping in release builds. - Signed backing types no longer allow component-local signs to create negative magnitudes inside stored ratios; component-local signed-minimum inputs now fail deterministically.
GenericFractionandDynaIntradix parsing no longer panic for bases outside 2 through 36; they returnParseError::UnsupportedBaseinstead of forwarding invalid bases to their backing integer implementations.
- Breaking:
-
0.16.009 Aug 2026Release notes
Open source →[0.16.0] - 2026-08-09
Changed
- Replaced optional
lazy_staticusage withstd::sync::OnceLockandnum-bigintconstants for approximation accuracy multipliers (special thanks to Expyron for thestd::sync::OnceLockpatch). - Breaking: Rust 1.70 is now the minimum supported Rust version (MSRV).
Fixed
- Fraction and Decimal parsing now routes zero-denominator inputs to signed infinity or NaN (including optional Unicode
from_unicode_str) rather than panicking. - Restored Decimal
Ord/PartialOrd/Eq/Hashconsistency 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. - Added PostgreSQL
NUMERICinfinity round-trip support for bothFractionandDecimal, encoding/decoding±Infinityusing0xD000/0xF000markers and documenting PostgreSQL 14+/unconstrainedNUMERICrequirements.
Release notes
Open source →Changed
- Replaced optional
lazy_staticusage withstd::sync::OnceLockandnum-bigintconstants for approximation accuracy multipliers (special thanks to Expyron for thestd::sync::OnceLockpatch). - Breaking: Rust 1.70 is now the minimum supported Rust version (MSRV).
Fixed
- Fraction and Decimal parsing now routes zero-denominator inputs to signed infinity or NaN (including optional Unicode
from_unicode_str) rather than panicking. - Restored Decimal
Ord/PartialOrd/Eq/Hashconsistency 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. - Added PostgreSQL
NUMERICinfinity round-trip support for bothFractionandDecimal, encoding/decoding±Infinityusing0xD000/0xF000markers and documenting PostgreSQL 14+/unconstrainedNUMERICrequirements.
- Replaced optional
-
0.15.421 Apr 2026Release notes
Open source →What's Changed
- feat: add from_fraction_with_precision by @javamonn in #109
- Remove deprecations & fix lints by @dnsl48 in #111
New Contributors
Full Changelog: 0.15.3...0.15.4
Release notes
Open source →Added
from_fraction_with_precisionhelper
Changed
- Captured the crate edition explicitly in
Cargo.tomlasedition = "2015". numcrate min required version is now0.4.3
Fixed
- Tidy-up deprecation and clippy warnings, plus small docs/licence metadata fixes.
- Corrected the crate-level Unicode example/docs so default
cargo testno longer fails withoutwith-unicode.
-
0.15.312 May 2024Release notes
Open source →numcrate min required version is now0.4.2(The one where ConstOne and ConstZero were introduced)
-
0.15.227 Apr 2024 withdrawnRelease notes
Open source →[0.15.2] - 2024-04-28
Added
- GenericFraction ConstOne and ConstZero trait implementations (special thanks to Raimundo Saona, aka @saona-raimundo)
Release notes
Open source →Added
- GenericFraction ConstOne and ConstZero trait implementations (special thanks to Raimundo Saona, aka @saona-raimundo)
-
0.15.111 Feb 2024Release notes
Open source →Added
- "with-unicode" feature implementation to format (and parse) floats with Unicode characters (special thanks to @feefladder)
Release notes
Open source →Added
- "with-unicode" feature implementation to format (and parse) floats with Unicode characters (special thanks to @feefladder)
-
0.15.001 Jan 2024Release notes
Open source →Added
- GenericFraction try_from/try_into implementations for primitive types (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize, f32, f64)
- GenericFraction try_from/try_into implementations for BigInt/BigUint ("with-bigint" feature)
- GenericDecimal try_from/try_into implementations for primitive types (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize, f32, f64)
- GenericDecimal try_from/try_into implementations for BigInt/BigUint ("with-bigint" feature)
- Tests for all GenericDecimal ops (overloadable operators - std::ops)
Changed
- GenericDecimal ops (overloadable operators) refactoring. Each operator is now implemented separately in its own module, allowing decoupled code with its own optimisations and tests.
Fixed
- PartialOrd will now reuse Ord implementation where possible (refactor to make clippy happier)
- Fixed logic in
sub_assignandchecked_subthat could sometimes produce incorrect results for a couple of edge cases with a negative zero (-0) as an operand.
-
0.14.027 Sep 2023Release notes
Open source →Added
approxmodule with "Approximate mathematical operations",fn sqrt(special thanks to @squ1dd13 for the contribution!)with-approxfeature, enabling theapproxmodule
Release notes
Open source →Added
approxmodule with "Approximate mathematical operations",fn sqrt(special thanks to @squ1dd13 for the contribution!)with-approxfeature, enabling theapproxmodule
-
0.13.124 Feb 2023Release notes
Open source →[0.13.1] - 2023-02-25
Added
- Clippy hint to allow manual filtering in GenericFraction::to_i64 implementation
- A couple of tests for floor/ceil functions
Fixed
- ceil & floor incorrect behaviour for negative numbers (special thanks to Morris Hansing aka morri2)
Release notes
Open source →Added
- Clippy hint to allow manual filtering in GenericFraction::to_i64 implementation
- A couple of tests for floor/ceil functions
Fixed
- ceil & floor incorrect behaviour for negative numbers (special thanks to Morris Hansing aka morri2)
-
0.13.001 Jan 2023Release notes
Open source →[0.13.0] - 2023-01-01
Changed
PartialCmpnow comparesNaNwith the other values and returns it as the smallest possible value. Thus,NaN < -Inf.
Fixed
partial_cmpnow behaves exactly the same ascmp(PartialOrd is now consistent with Ord).
This fixes an issue introduced in0.12.2with the implementation ofOrd,
whereOrdwould behave differently fromPartialOrdwithNaNvalues.
Special thanks to Hsingai Tigris Altaica aka DrAlta for fixing this.
Release notes
Open source →Changed
PartialCmpnow comparesNaNwith the other values and returns it as the smallest possible value. Thus,NaN < -Inf.
Fixed
partial_cmpnow behaves exactly the same ascmp(PartialOrd is now consistent with Ord). This fixes an issue introduced in0.12.2with the implementation ofOrd, whereOrdwould behave differently fromPartialOrdwithNaNvalues. Special thanks to Hsingai Tigris Altaica aka DrAlta for fixing this.
-
0.12.204 Dec 2022Release notes
Open source →Added
Ordtrait implementation for GenericFraction and GenericDecimal (special thanks to Hsingai Tigris Altaica aka DrAlta)
-
0.12.119 Oct 2022Release notes
Open source →Added
- Support to
addcastable values (e.g.f + 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
subcastable values (e.g.f - 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
divcastable values (e.g.f / 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
mulcastable values (e.g.f * 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
add_assigncastable values (e.g.f += 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
sub_assigncastable values (e.g.f -= 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
div_assigncastable values (e.g.f /= 1u8, 1u8 will be transparently casted toFractionwith.into()) - Support to
mul_assigncastable values (e.g.f *= 1u8, 1u8 will be transparently casted toFractionwith.into())
Changed
- Refactoring of the fraction module. std::ops implementations moved into separate submodules.
- generic::read_generic_integer performance improved for when target type matches source (~83% improvement, which is 5 times faster). As the result this can affect GenericFraction::from performance for non-float types.
- From<(A, B)> implementation is migrated to GenericFraction::new_generic (~85% performance improvement and with no heap allocations, which is ~7 times faster).
- Support to
-
0.12.013 Oct 2022Release notes
Open source →Changed
numversion0.4is now required (0.2,0.3are no longer supported)- Multiple functions made const in GenericFraction, GenericDecimal and fraction::display::Format Special thanks to Stijn Frishert (aka stijnfrishert).
Deprecated
- fn
decimal::GenericDecimal::apply_refis deprecated.
Removed
- Removed deprecated fn
decimal::GenericDecimal::from_decimal_str. UseFromStr::from_strinstead. - Removed deprecated fn
fraction::GenericFraction::from_decimal_str. UseFromStr::from_strinstead. - Removed deprecated fn
fraction::GenericFraction::format_as_decimal. Useformat!(\"{:.1$}\", fraction, precision)instead. - Removed deprecated fn
fraction::GenericFraction::new_raw_neg. Usenew_raw_signedinstead.
-
0.11.217 Sep 2022Release notes
Open source →DynaIntnow implements serdeSerialize & Unserialize(Thanks to Richard Davies aka @optevo for the contribution!)
-
0.11.107 Aug 2022Release notes
Open source →Fixed
- Fraction::from_str trims trailing zeroes before calculating denom (Thanks to @khigia for the contribution!)
-
0.11.018 Jun 2022Release notes
Open source →Changed
numdependency versions extended from0.2to>=0.2,<5(Thanks to Joel Natividad aka jqnatividad for the contribution!)lazy_staticdependency versions extended from1.1to1
-
0.10.006 Feb 2022Release notes
Open source →Added
std::str::FromStrtrait implementation for GenericFraction and GenericDecimal Special thanks to Scott Wilson for the contribution- Deprecated
GenericFraction::from_decimal_strandGenericDecimal::from_decimal_strin favour of ofstd::str::FromStr
-
0.9.021 Aug 2021Release notes
Open source →Added
- Default trait implementation for GenericFraction and GenericDecimal
postgres-types: ^0.2andbytes: 1are new optional dependencies (feature: with-postgres-support)GenericFraction::new_raw_signedconstructor
Changed
- Juniper supported version upgraded from 0.11 to 0.15
- Postgres supported version upgraded from 0.15 to 0.19 (might be down to 0.16, but untested).
Removed
postgrescrate is not a dependency any longer- Deprecated fn
GenericFraction::format_as_decimalis removed
-
0.8.016 Dec 2020Release notes
Open source →Changed
- More efficient f32/f64 conversion to Fractions and Decimals (up to 10 times faster and not using memory allocation anymore) Special thanks to Christopher Rabotin for the contribution!
-
0.7.004 Dec 2020Release notes
Open source →Added
- fraction::display::Format implements Clone trait (becomes cloneable)
- fraction::Sign implements PartialOrd and Ord traits (becomes orderable)
- GenericDecimal::calc_precision max_precision optional argument to limit the calculation
Changed
- Decimal::from_fraction now limits precision calculation to 255
- rustfmt for the whole codebase
- small readability refactoring for some methods
-
0.6.306 May 2020Release notes
Open source →Added
- std::iter::{Sum, Product} implemented for GenericFraction and GenericDecimal
-
0.6.219 May 2019 -
0.6.128 Mar 2019Release notes
Open source →Added
- dynaint,
Into<BigUint>implementation - fraction,
GenericFraction::into_fraction<I>method implementation
- dynaint,
-
0.6.004 Feb 2019Release notes
Open source →Added
- division::divide_to_callback implementation. Some other functions refactored to be using it internally
- fraction::display module implementation, Fraction ::std::fmt::Display implementation supporting all the features of the std::fmt::Formatter
- Decimal ::std::fmt::Display implementation supporting all the features of the std::fmt::Formatter
Changed
- Juniper updated to 0.11
- GenericFraction::format_as_decimal is now deprecated. Use format! macro instead, or division module if you need more control
- division module functions signatures now have flags for trailing zeroes
Removed
- Deprecated functions
-
0.5.025 Nov 2018Release notes
Open source →Changed
- Division module API; functions to return division state for later reuse (remainder and divisor)
-
0.4.118 Oct 2018 -
0.4.009 Oct 2018Release notes
Open source →Bugs
Hashimplementation forGenericFractionnow returns equal hashes for negative and positive zeroes
Added
- Lossless division, fraction decimal representation with infinite precision
- Decimal type, built on top of Fraction
- PostgreSQL integration
- Juniper integration
- Types with dynamic growth into heap on overflow
- Generic integer conversions (usize -> i8, i8 -> u8, etc)
- Examples and documentation for new features
- Re-exporting the bunch of
numtraits so that the library can be used without explicit dependency onnum
Refactoring
- The lib has been split into modules with separate features
Modules
convertmodule with traits for optimistic convesiondecimalmodule withGenericDecimalimplementation,JuniperandPostgreSQLintegration for itdivisionmodule with lossless infinite division implementation without memory allocationdynaintmodule withDynaInttype implementation (dynamically growing integer)errormodule with shared library error typesfractionmodule withGenericFractionimplementation,JuniperandPostgreSQLintegration for itgenericmodule withGenericIntegertrait implementation, generic integer types conversionpreludemodule with some predefined type aliases such asFractionandDecimaltestsmodule with some tests
Features
with-bigint(default), integration withnum::{BigInt, BigUint}typeswith-decimal(default),GenericDecimaltype implementationwith-dynaint(default),DynaInttype implementationwith-juniper-support,Juniper 0.10integrationwith-postgres-support,Postgres 0.15integration
Changes
GenericFractionredundant methods deprecated:new_nan,new_inf,new_inf_neg,into_big,format_as_float
-
0.3.709 Nov 2017 -
0.3.626 Jul 2017Release notes
Open source →Bugs
T in GenericFraction<T>isClone + Integerfrom now onwards (thanks to Taryn Hill aka Phrohdoh)
-
0.3.515 Apr 2017Release notes
Open source →Changed
numpackage dependency version updated from "0.1.36" to "0.1.37"
-
0.3.410 Dec 2016Release notes
Open source →Bugs
fn _newnow returns NaN for 0/0 (was Infinity before)fn signnow returns values for GenericFraction::Infinite values toofn neg_zeronow returns zero with negative sign (was positive before)fn recipnow handles zero values gracefully (does not panic, returns Infinity)
Added
- Lots of documentation
-
0.3.317 Nov 2016Release notes
Open source →Refactoring
- More efficient implementation of
From<[unsigned ints]> - More generic implementation of
From<BigInt>
- More efficient implementation of
-
0.3.212 Nov 2016Release notes
Open source →Refactoring
Zero::is_zeroto be used everywhere in math, rather than making new zero vals + comparing with them
Added
fn new_nanconstructorfn new_infconstructorfn new_inf_negconstructor
-
0.3.111 Nov 2016Release notes
Open source →Added
fn format_as_floatimplemented forGenericFraction<T>(it was only available for BigFraction before)
Changed
Into<T>to be used in bounds rather thanFrom<N>, since it's more flexible (thanks to Alexander Altman for the patch)- number of bug fixes within
fn format_as_float+ test coverage
-
0.3.007 Nov 2016Release notes
Open source →Added
From<(N, D)>generic implementation (through std::fmt::Display)
Changed
GenericFraction<T>copy semantic to be applied only whenT: CloneGenericFractionimpl, constructors refactoring (new, new_raw)numupgraded up to0.1.36(from0.1.34)
Removed
fn newdoes not perform type casting through fmt::Display anymore (that functionality moved out asFrom<(N, D)>)
-
0.2.217 Sep 2016Release notes
Open source →Added
impl From<num::BigInt> for BigFractionimpl From<num::BigUint> for BigFraction
-
0.2.127 Aug 2016 -
0.2.027 Aug 2016Release notes
Open source →Added
- num crate is a dependency now
GenericFraction<T>implemented uponnum::Ratio<T>BigFractionimplementation based onnum::BigRational(using heap)num::traits::Boundedtrait implementedfn min_positive_valueimplementednum::traits::ToPrimitivetrait implementednum::traits::Signedtrait implementedFrom<f64>trait implementation now relies onformat!macro instead off64::fractBigFractionstruct usingnum::BigUintfn format_as_floatfor BigFraction has been implemented
Changed
- The codebase has been rewritten and the license has been changed from
LGPL-3toMIT/Apache2dual - no more convertions into INFINITY on arithmetic overflows
fn to_f64now returnsOption<f64>instead off64(num::trait::ToPrimitiveimplementation)Fromtrait implementation usesfmt::Displayfrom now on
Removed
fn unpackremovedstd::cmp::Ordimplementation removed in regard toNaNvalues
-
0.1.024 Jan 2016