num
crate min required version is now0.4.2
- 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)
- 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)
- GenericDecimal ops (overloadable operators) refactoring. Each operator is now implemented separately in its own module, allowing decoupled code with its own optimisations and tests.
- PartialOrd will now reuse Ord implementation where possible (refactor to make clippy happier)
- Fixed logic in
sub_assign
andchecked_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!)with-approx
feature, enabling theapprox
module
- Clippy hint to allow manual filtering in GenericFraction::to_i64 implementation
- A couple of tests for floor/ceil functions
- ceil & floor incorrect behaviour for negative numbers (special thanks to Morris Hansing aka morri2)
PartialCmp
now comparesNaN
with the other values and returns it as the smallest possible value. Thus,NaN < -Inf
.
partial_cmp
now behaves exactly the same ascmp
(PartialOrd is now consistent with Ord). This fixes an issue introduced in0.12.2
with the implementation ofOrd
, whereOrd
would behave differently fromPartialOrd
withNaN
values. Special thanks to Hsingai Tigris Altaica aka DrAlta for fixing this.
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 toFraction
with.into()
) - Support to
sub
castable values (e.g.f - 1u8
, 1u8 will be transparently casted toFraction
with.into()
) - Support to
div
castable values (e.g.f / 1u8
, 1u8 will be transparently casted toFraction
with.into()
) - Support to
mul
castable values (e.g.f * 1u8
, 1u8 will be transparently casted toFraction
with.into()
) - Support to
add_assign
castable values (e.g.f += 1u8
, 1u8 will be transparently casted toFraction
with.into()
) - Support to
sub_assign
castable values (e.g.f -= 1u8
, 1u8 will be transparently casted toFraction
with.into()
) - Support to
div_assign
castable values (e.g.f /= 1u8
, 1u8 will be transparently casted toFraction
with.into()
) - Support to
mul_assign
castable values (e.g.f *= 1u8
, 1u8 will be transparently casted toFraction
with.into()
)
- 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).
num
version0.4
is now required (0.2
,0.3
are no longer supported)- Multiple functions made const in GenericFraction, GenericDecimal and fraction::display::Format Special thanks to Stijn Frishert (aka stijnfrishert).
- fn
decimal::GenericDecimal::apply_ref
is deprecated.
- Removed deprecated fn
decimal::GenericDecimal::from_decimal_str
. UseFromStr::from_str
instead. - Removed deprecated fn
fraction::GenericFraction::from_decimal_str
. UseFromStr::from_str
instead. - Removed deprecated fn
fraction::GenericFraction::format_as_decimal
. Useformat!(\"{:.1$}\", fraction, precision)
instead. - Removed deprecated fn
fraction::GenericFraction::new_raw_neg
. Usenew_raw_signed
instead.
DynaInt
now implements serdeSerialize & 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 from0.2
to>=0.2,<5
(Thanks to Joel Natividad aka jqnatividad for the contribution!)lazy_static
dependency versions extended from1.1
to1
std::str::FromStr
trait implementation for GenericFraction and GenericDecimal Special thanks to Scott Wilson for the contribution- Deprecated
GenericFraction::from_decimal_str
andGenericDecimal::from_decimal_str
in favour of ofstd::str::FromStr
- Default trait implementation for GenericFraction and GenericDecimal
postgres-types: ^0.2
andbytes: 1
are new optional dependencies (feature: with-postgres-support)GenericFraction::new_raw_signed
constructor
- 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).
postgres
crate is not a dependency any longer- Deprecated fn
GenericFraction::format_as_decimal
is removed
- 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!
- 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
- Decimal::from_fraction now limits precision calculation to 255
- rustfmt for the whole codebase
- small readability refactoring for some methods
- std::iter::{Sum, Product} implemented for GenericFraction and GenericDecimal
- std::error::Error implemented for error::ParseError
- dynaint,
Into<BigUint>
implementation - fraction,
GenericFraction::into_fraction<I>
method implementation
- 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
- 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
- Deprecated functions
- Division module API; functions to return division state for later reuse (remainder and divisor)
DynaInt
, initialstd::fmt::Display
implementation
Hash
implementation forGenericFraction
now returns equal hashes for negative and positive zeroes
- 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
num
traits so that the library can be used without explicit dependency onnum
- The lib has been split into modules with separate features
convert
module with traits for optimistic convesiondecimal
module withGenericDecimal
implementation,Juniper
andPostgreSQL
integration for itdivision
module with lossless infinite division implementation without memory allocationdynaint
module withDynaInt
type implementation (dynamically growing integer)error
module with shared library error typesfraction
module withGenericFraction
implementation,Juniper
andPostgreSQL
integration for itgeneric
module withGenericInteger
trait implementation, generic integer types conversionprelude
module with some predefined type aliases such asFraction
andDecimal
tests
module with some tests
with-bigint
(default), integration withnum::{BigInt, BigUint}
typeswith-decimal
(default),GenericDecimal
type implementationwith-dynaint
(default),DynaInt
type implementationwith-juniper-support
,Juniper 0.10
integrationwith-postgres-support
,Postgres 0.15
integration
GenericFraction
redundant methods deprecated:new_nan
,new_inf
,new_inf_neg
,into_big
,format_as_float
- Fix comparisons with negative numbers
T in GenericFraction<T>
isClone + Integer
from now onwards (thanks to Taryn Hill aka Phrohdoh)
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 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)
- Lots of documentation
- More efficient implementation of
From<[unsigned ints]>
- More generic implementation of
From<BigInt>
Zero::is_zero
to be used everywhere in math, rather than making new zero vals + comparing with them
fn new_nan
constructorfn new_inf
constructorfn new_inf_neg
constructor
fn format_as_float
implemented forGenericFraction<T>
(it was only available for BigFraction before)
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
From<(N, D)>
generic implementation (through std::fmt::Display)
GenericFraction<T>
copy semantic to be applied only whenT: Clone
GenericFraction
impl, constructors refactoring (new, new_raw)num
upgraded up to0.1.36
(from0.1.34
)
fn new
does not perform type casting through fmt::Display anymore (that functionality moved out asFrom<(N, D)>
)
impl From<num::BigInt> for BigFraction
impl From<num::BigUint> for BigFraction
- Package description has been changed
- num crate is a dependency now
GenericFraction<T>
implemented uponnum::Ratio<T>
BigFraction
implementation based onnum::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 onformat!
macro instead off64::fract
BigFraction
struct usingnum::BigUint
fn format_as_float
for BigFraction has been implemented
- The codebase has been rewritten and the license has been changed from
LGPL-3
toMIT/Apache2
dual - no more convertions into INFINITY on arithmetic overflows
fn to_f64
now returnsOption<f64>
instead off64
(num::trait::ToPrimitive
implementation)From
trait implementation usesfmt::Display
from now on
fn unpack
removedstd::cmp::Ord
implementation removed in regard toNaN
values
- Basic implementation