Fraction
Lossless float that may be used in matching, ordering and hashing
More documentation available on docs.rs.
- The main goal of Fraction is to keep precision that floats cannot do
- Fractions can be used for matching and comparisons and thus for hashing
- Base arithmetic implemented upon
numcrate (rationalmodule) Fractionstruct implementation uses twou64numbers and arithmetic on stackBigFractionstruct implementation uses two limitlessBigUintnumbers and arithmetic on heap
Examples
Simple arithmetic
use Fraction;
Using as keys for a HashMap
use HashMap;
use Fraction;
Comparison
use Fraction;
Change Log
[0.3.4] - 2016-12-11
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.3] - 2016-11-18
Refactoring
- More efficient implementation of
From<[unsigned ints]> - More generic implementation of
From<BigInt>
[0.3.2] - 2016-11-13
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.1] - 2016-11-12
Added
fn format_as_floatimplementation for GenericFraction (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.0] - 2016-11-08
Added
- From<(N, D)> generic implementation (through std::fmt::Display)
Changed
- GenericFraction copy semantic to be applied only when
T: Clone - GenericFraction impl, 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.2] - 2016-09-17
Added
impl From<num::BigInt> for BigFractionimpl From<num::BigUint> for BigFraction
[0.2.1] - 2016-08-28
Changed
- Package description has been changed
[0.2.0] - 2016-08-28
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.0] - 2016-01-24
Added
- Basic implementation