- Bumped
borsh
andcriterion
dependencies to the latest versions. (#568) - Removed erroneous debug statements in
serde-with-str
feature. (#571)
Thanks @attila-lin for your help bumping dependencies.
- Implement
TryFrom<&str>
forDecimal
(#560)
- Explicit string deserialize for
Option<Decimal>
when usingserde-with-str
(#565) - Fix for
rescale
preventingDecimal::ZERO
to be rescaled to an invalid precision (#566)
Thank you to @c410-f3r for your diligent help adding features to this library!
- Added
Copy
/Clone
traits forrkvy::Archive
(#539) - Support precision for scientific notation formatting (#555, #557)
- Fixed edge case parsing of strings whereby it would incorrectly error instead of round (#541)
- Update diesel feature to use release version (#546)
- Updated documentation to include
cargo-edit
instructions (#538) - Start using new feature resolver for cargo dependencies (#551)
- Optional serde deserialization avoids using
deserialize_any
except in explicit use cases (#558)
This release wouldn't have been possible without the help of the community. Special call out and thank you to @icy-ux, @CAD97, @nicksenger, @c410-f3r and @yongqli.
- Fixes
docs.rs
failing to compile due to mutually exclusivediesel1
anddiesel2
features. The previouscompile_error!
was in fact an anti-pattern. Consequently, if bothdiesel1
anddiesel2
features are specified then it will favordiesel2
. This helps prevent any conflict scenarios and ultimately resolves the downstreamdocs.rs
issue.
serde-with-*
features now supportOption<T>
variants (#524).- Implementation support for
core::iter::Product
(#525). - Diesel
2.0.0-rc.1
support viadb-diesel2-mysql
anddb-diesel2-postgres
features. (#533 and (#532)).
- Fixes a silent overflow in
from_str
when parsingDecimal::MAX
with a fractional portion. (#530).
Thank you to @Guara92 who made the initial diesel2
PR which made parallel implementation a breeze! Also, once again, thank you
to @c410-f3r for implementing the missing Product
trait!
- Expands
rand
support to implementSampleUniform
to allow forrng.gen_range
calls (#519) - Adds
rkyv
framework support for zero-cost (de)serialization (#520)
A big thank you to @lukesneeringer and @dovahcrow for your help building features for this release.
- Introduces new feature
rand
which allows for random number generation withinrust_decimal
(#517). - Upgrade to Rust 2021 and remove unnecessary dependencies to improve build speed (#513, #516)
- Some test scoping improvements to ensure we capture as many test combinations as possible (#503, #504).
A big thank you to @c410-f3r for their contributions to this release!
Fixes issue with no_std
compatability introduced in 1.23.0
(#501).
- Add
BorschSchema
support for theborsh
feature (#498). - Implement
TryFrom
for Decimal primitive types (#493). - Fix
to_i64
to supporti64::MIN
(#496). - Implement
Inv
fromnum_traits
(#495). - Some minor housekeeping tasks (#487, #490).
Thank you @turion, @arthurprs and @jnitard for your help with this release.
- Add support for
borsh
serialization/deserialization (#478). - Fixes an issue with
serde-with-str
where it wasn't behaving the same asserde-str
when usingbincode
(#484). - Added
must_use
tois_sign_negative
andunpack
(#482). - Minor documentation fixes.
Thank you @jkbpvsc for your help in this release.
- Saturating op variants have been added:
saturating_add
,saturating_sub
andsaturating_mul
(#464) - Fixes issue with
log10
values0 < x < 1
(#469) - Various documentation fixes/cleanup.
Thank you @c410-f3r for your work in this release!
- Additional fuzz testing for deserialize (#452)
- Documentation fix for rounding strategy (#458)
from_str
is now over 4x faster, utilizing const generics and TCO (#456)- Fixed
from_str
issue with rounding issues when too many digits in source string. (#453) - New
serde-with
functionality for greater configurability when usingserde
(#459) - Various maintenance tasks (#460)
This is truly a collaborative release and has some significant contributions from the community. A huge thank you to everyone involved:
This is a minor dot release and contains library updates (#334) and
expanded scope in prelude
to include num_traits::Signed
(#450).
While subtle, it also expands the way towards some bigger improvements including variable precision.
Of a larger note, the minimum Rust compiler version has been updated so we can start utilizing various compiler features
(such as const generics). The miminum compiler version is now 1.51.0
.
Thank you to @c410-f3r and @jracollins for your contributions to this release.
- Fixes integer handling for
to_f64
when scale is set to0
. #443. Thank you @anatols for creating this fix. - Add support for Rocket Forms using the feature flag
rocket-traits
. #445. Thank you @Misterio77 for putting this together. - Add Diesel MySQL support, enabled by the feature flag
db-diesel-mysq
. #446.
- Fixes panic when display precision was specified greater than 30. #428.
- Binds
deserialize
so that invalid scale values cannot be set. This may be a breaking change for some users leveraging this in aconst
function. #428. - Fixes an issue in
round_sf
whereby integral values that started with a 0 or 1 would output incorrect rounded numbers. #430, #437. - Adds
from_f32_retain
andfrom_f64_retain
functions which allow parsing a floating point number and retaining any excess precision. #438.
- Implement
sin
/cos
/tan
functions which are enabled within themaths
feature. #413. - Implement
round_sf
andround_sf_with_strategy
to enable significant figure rounding. #421 - Remove unnecessary
std
feature fromarrayvec
usage #417. - Adhoc benchmarking and fuzz tooling improvements #412, #415, #416, #418.
Thank you to @c410-f3r for all your help with fuzz and benchmarking improvements!
A minor bug and feature release which adds a couple of new functions as well as cleans up some documentation:
- Support for serializing to float without converting to float via the
serde-arbitrary-precision
feature. #402. Thanks @JamesHinshelwood! for finding and fixing this! - Add
log10
support to themaths
feature. Please note thatln
andlog10
will now panic on invalid input since both functions have achecked_*
equivalent. This is the preferred approach going forward, however if you would like to re-enable the previous behavior please use themaths-nopanic
feature. #397. - Added further constants to the
Decimal
library includingTWO
,TEN
,ONE_HUNDRED
,ONE_THOUSAND
, andNEGATIVE_ONE
. #400. - Fixes serialization issue for
-0
whereby-
would be output #406. Thanks @edwardycl! - Fixes float rounding before return in
to_f64
. #401. - Added
BUILD.md
file to help people get set up with Rust Decimal locally and cleaned up some documentation examples.
Fixes an issue #398 where Decimal::ZERO.ln()
would panic rather than returning Decimal::ZERO
. This
aligns the behavior with calling ln
on negative decimals.
Thank you to @SebRollen for finding and fixing this.
Fixes an overflow issue during division under some specific circumstances. (#392)
A bug fix release following on from 1.14.0
:
- Fixes an issue whereby in some cases when subtracting a 64 bit
Decimal
a negating overflow would occur during underflow. #384. Thank you to @c410-f3r for finding this as part of fuzz testing. - Fixes an issue with
exp
whereby negative values lost accuracy due to inability to converge. #378. Thank you to @schungx for finding this and proposing a fix. - Fixes some documentation issues.
- Added
checked_exp
andchecked_norm_pdf
functions #375. - Fixes bug in division under certain circumstances whereby overflow would occur during rounding. #377
- Documentation improvements
Thank you to @falsetru, @schungx and @blasrodri for your help with this release!
This is a minor update to the library providing a few new features and one breaking change (I'm not using semver properly here sorry).
#[must_use]
added to functions to provide additional compiler hints.try_from_i128_with_scale
function added to safely handlei128
overflow errors.- New
c-repr
feature added which will ensure that#[repr(C)]
is used on theDecimal
type. Thanks @jean-airoldie. - Small improvements to
from_scientific
. It now supports a wider range of values as well has slightly faster performance. - Support for negative and decimal
pow
functions. This is breaking sincepowi(u64)
has been renamed topowi(i64)
. If you want to continue usingu64
arguments then please usepowu(u64)
. The fractional functions should be considered experimental for the time being and may have subtle issues that still need ironing out. Functions are now:powi
,checked_powi
- When the exponent is a signed integer.powu
,checked_powu
- When the exponent is an unsigned integer.powf
,checked_powf
- When the exponent is a floating point number. Please note, numbers with a fractional component will use an approximation function.powd
,checked_powd
- When the exponent is aDecimal
. Please note, numbers with a fractional component will use an approximation function.
Adds num_traits::One
back to rust_decimal::prelude
to prevent unnecessary downstream dependency breakages. Thanks @spearman.
Fixes an issue #361 when rounding a small number towards zero.
Fixes small regression whereby 0 - 0
was producing -0
. Thank you @KonishchevDmitry for
providing a swift fix (#356).
Added num_traits::Zero
back to rust_decimal::prelude
to prevent unnecessary downstream dependency breakages.
This version releases faster operation support for add
, sub
, cmp
, rem
and mul
to match the renewed div
strategy.
It does this by leveraging 64 bit support when it makes sense, while attempting to still keep 32 bit optimizations in place.
To ensure correct functionality, thousands more tests were included to cover a wide variety of different scenarios
and bit combinations. Compared to previous operations, we get the following speed improvements:
add
- up to 2.2x fasterdiv
- up to 428x fastermul
- up to 1.8x fasterrem
- up to 1.08x fastersub
- up to 2.5x faster
Of course, if old functionality is desired, it can be re-enabled by using the legacy-ops
feature.
Other improvements include:
- Remove unnecessary
String
allocation when parsing a scientific number format. Thanks @thomcc for the fix #350. - Fixes overflow bug with
sqrt
when using the smallest possible representable number. #349. - Some minor optimizations in the
maths
feature. Future work will involve speeding up this feature by keeping operations in an internal format until required. - Added associated constants for
MIN
,MAX
andZERO
. Deprecatedmin_value()
andmax_value()
in favor of these new constants. -0
now gets corrected to0
. During operation rewrite I needed to consider operations such as-0 * 2
- in cases like this I opted towards0
always being the right number and-0
being superfluous (since+0 == -0
). Consequently, parsing-0
etc in general will automatically be parsed as0
. Of course, this may be a breaking change so if this functionality is required then please create an issue with the use case described.- Small breaking change by renaming
is_negative
tonegative
inUnpackedDecimal
. - Some internal housekeeping was made to help make way for version 2.0 improvements.
This is a documentation only release and has no new functionality included. Thank you @c410-f3r for the documentation fix.
This release includes a number of bug fixes and ergonomic improvements.
- Mathematical functionality is now behind a feature flag. This should help optimize library size when functions such as
log
andpow
are not required (e.g. simple financial applications). Mathematical functionality is now behind themaths
feature flag. #321. - Numerous test coverage improvements to ensure broader coverage. #322, #323
- Various documentation improvements. #324, #342
- Fixes
u128
andi128
parsing. #332 - Implemented
Checked*
traits fromnum_traits
. #333. Thank you @teoxoy - Added
checked_powi
function tomaths
feature. #336 - Updated
from_parts
to avoid accidental scale clobbering. #337 - Added support for the
Arbitrary
trait forrust-fuzz
support. This is behind the feature flagrust-fuzz
. #338 - Fixes
e^-1
returning an incorrect approximation. #339 - Revamp of
RoundingStrategy
naming and documentation (#340). The old naming was ambiguous in interpretation - the new naming convention follows guidance from other libraries to ensure an easy to follow scheme. TheRoundingStrategy
enum now includes:MidpointNearestEven
(previouslyBankersRounding
)MidpointAwayFromZero
(previouslyRoundHalfUp
)MidpointTowardZero
(previouslyRoundHalfDown
)ToZero
(previouslyRoundDown
)AwayFromZero
(previouslyRoundUp
)ToNegativeInfinity
- new rounding strategyToPositiveInfinity
- new rounding strategy
- Added function to access
mantissa
directly. #341 - Added a feature to
rust_decimal_macros
to make re-exporting the macro from a downstream crate more approachable. Enabling thereexportable
feature will ensure that the generated code doesn't requirerust_decimal
to be exposed at the root level. #343
- Fixes bug in bincode serialization where a negative symbol causes a buffer overflow (#317).
- Fixes a bug introduced in division whereby certain values when using a large remainder cause an incorrect results (#314).
- Fixes bug introduced in
neg
whereby sign would always be turned negative as opposed to being correctly negated.
Thank you KonishchevDmitry for finding and fixing this.
- Upgrade
postgres
to0.19
andtokio-postgres
to0.7
. - Faster
serde
serialization by preventing heap allocation. - Alternative division algorithm which provides significant speed improvements. The new algorithms are enabled by default,
but can be disabled with the feature:
legacy-ops
. Further work to improve other operations will be made available in future versions. - Add
TryFrom
forf32
/f64
to/from Decimal
Thank you for the the community help and support for making this release happen, in particular: jean-airoldie, gakonst, okaneco and c410-f3r.
- Added arbitrary precision support for
serde_json
deserialization (#283) - Add
u128
andi128
FromPrimitive
overrides to prevent default implementation kicking in. Also adds defaultFrom
interceptors to avoid having to use trait directly. (#282) - Alias
serde-bincode
asserde-str
to make usage clearer (#279) - Adds scientific notation to format strings via
UpperExp
andLowerExp
traits. (#271) - Upgrade
tokio-postgres
andpostgres
libraries. - Add statistical function support for
powi
,sqrt
,exp
,norm_cdf
,norm_pdf
,ln
&erf
(#281, #287) - Allow
sum
across immutable references (#280)
Thank you for all the community help and support with this release, in particular xilec, remkade and Anders429.
Make std
support the default to prevent breaking downstream library dependencies. To enable no_std
support please set
default features to false and opt-in to any required components. e.g.
rust_decimal = { default-features = false, version = "1.8.0" }
no_std
support added to Rust Decimal by default.std
isn't required to use Rust Decimal, however can be enabled by using thestd
feature. #190- Fixes issue with Decimal sometimes losing precision through
to_f64
. #267. - Add
Clone
,Copy
,PartialEq
andEq
derives toRoundingStrategy
. - Remove Proc Macro hack due to procedural macros as expressions being stabilized.
- Minor optimizations
Thank you to @c410-f3r, @smessmer and @KiChjang.
- Enables
bincode
support via the featureserde-bincode
. This provides a long term fix for a regression that was introduced in version0.6.5
(tests now cover this case!). Issue 43. - Fixes issue where
rescale
on zero would not have an affect. This was due to an early exit condition which failed to set the new scale. Issue 253. - Add
min
andmax
functions, similar to whatf32
andf64
provide. Thank you @michalsieron. - Updates documentation for
is_sign_positive
andis_sign_negative
to specify that the sign bit is being checked.
Please note: feature naming conventions have been modified, however backwards compatible aliases have been created where necessary. It's highly recommended that you move over to the new naming conventions as these aliases may be removed at a later date.
- Fixes issue with PostgreSQL conversions whereby certain inputs would cause unexpected outputs. Issue 241.
- Fixes issue with
from_str_radix
whereby rounding logic would kick in too early, especially with radix less than 10. Issue 242. - Fixes issue whereby
from_str
(implicityfrom_str_radix
) would panic when there was overflow and overflow significant digit was < 5. Issue 246. - Make
bytes
andbyteorder
optional since they're only used in thepostgres
feature and tests. - Fix edge case in
from_i128_with_scale
wheni128::MIN
was provided.
Thank you to @serejkaaa512, @AbsurdlySuspicious and @0e4ef622 for your contributions!
- Added additional
RoundStrategy
abilities:RoundUp
to always round up andRoundDown
to always round down. - Updated prelude to include expected structs and traits by default.
Special thank you to @jean-airoldie for adding the additional rounding strategies and to @pfrenssen for fixing an issue in the README.
- Performance improvements for
to_f64
when using a scale > 0.
Special thank you to @hengchu who discovered and resolved the issue!
- Allow uppercase "E" in scientific notation.
- Allow scientific notation in
dec!
macro. - Deprecate
set_sign
and replace withset_sign_positive
andset_sign_negative
. This is intended to improve the readability of the API. - Fixes precision issue when parsing
f64
values. The base 2 mantissa of the float was assuming guaranteed accuracy of 53 bit precision, however 52 bit precision is more accurate (f64
only). - Removes deprecated usage of
Error::description
.
- Replace
num
dependency withnum_trait
- implementedSigned
andNum
traits.
- Fixes issue whereby overflow would occur reading from PostgreSQL with high precision. The library now handles this by rounding high precision numbers as they're read as opposed to crashing (similar to other underflow situations e.g. 1/3).
- Retain trailing zeros from PostgreSQL. This ensures that the scale is maintained when serialized into the Decimal type.
- Fixes issue where -0 != 0 (these are now equivalent - thank you @hengchu for discovering).
- Improve hashing function so that the following property is true:
k1 == k2 -> hash(k1) == hash(k2)
- Update normalize function so that -0 normalizes to 0.
Special thanks to @hathawsh for their help in this release!
- Update to Postgres 0.17 and add postgres async/await support via
tokio-pg
- Added option for serializing decimals as float via
serde-float
Special thanks to @pimeys and @kaibyao!
Updates dependencies to prevent build issues.
Bug fix release:
- Fixes issue where scaling logic produced incorrect results when one arm was a high precision zero. Thank you @KonishchevDmitry!
Bug fix release:
- Fixes issue where
ToSql
was incorrectly calculating weight when whole portion = numeric portion. - Fixes issue where
Decimal::new
incorrectly handledi64::max_value()
andi64::min_value()
. - Fixes issue where
rem
operation incorrectly returned results whenscale
was required.
This release represents the start of semantic versioning and allows the library to start making fundamental improvements under
the guise of V2.0. Leading up to that I expect to release 1.x versions which will include adding
various mathematical functions such as pow
, ln
, log10
etc.
Version 1.0.0
does come with some new features:
- Checked Operations! This implements
checked_add
,checked_sub
,checked_mul
,checked_div
andchecked_rem
. - Fixes overflow from
max_value()
andmin_value()
fori32
andi64
. - Minor documentation improvements and test coverage.
Special thanks to @0e4ef622 for their help with this release!
- Add prelude to help num trait inclusion (
use rust_decimal::prelude::*
) - Add
Default
trait to the library. This is equivalent to usingDecimal::zero()
- Added assignment operators for references.
Special thanks to @jean-airoldie for his help with this release!
- Fall back to
from_scientific
whenfrom_str
fails during deserialization. Thanks @mattjbray! - Added basic
Sum
trait implementation
- Fixes a bug in
floor
andceil
where negative numbers were incorrectly handled.
- Macros are now supported on stable. This does use a hack for the meantime so due diligence is required before usage.
- Fixes issue when parsing strings where an underscore preceded a decimal point.
const_fn
support via a feature flag. In the future this will be the default option however in order to support older compiler versions is behind a feature flag.
- Macros (nightly) now output structural data as opposed to serialized data. This is fully backwards compatible and results in some minor performance improvements. Also, removed feature gate so that it can be compiled in stable.
- Fixes a string parsing bug when given highly significant numbers that require rounding.
- Bumped dependencies to remove some legacy serialization requirements.
Special thanks to @xilec, @snd and @AndrewSpeed for their help with this release.
- New rounding strategies introduced via
round_dp_with_strategy
. Previously default rounding support used bankers rounding by default whereas now you can choose to round the half way point either up or down. - PostgreSQL write performance improved so that it is at least 3 times faster than the previous implementation.
Debug
trait now outputs the actual decimal number by default to make it more useful within consuming libraries (e.g.criterion.rs
). To get something similar to the previous functionality you can use theunpack
argument - this is likely for corerust-decimal
library maintainers.- Various other performance improvements for common operations such as
rescale
,sub
anddiv
.
- Performance optimization for
add
.
- Introduces the
Neg
trait to support the ability to use-decimal_variable
. - Fixes bug with underflow on addition.
This release updates the published documentation only and is a no-op for functionality.
- Introduces
from_scientific
allowing parsing of scientific notation into the Decimal type. - Fixes a bug when formatting a number with a leading zero's.
- Fixes bug in
rescale
whereby scaling which invoked rounding incorrectly set the new scale for the left/right sides.
- Fixes bug in
cmp
whereby two negatives would return an incorrect result. - Further documentation examples
- Small improvements in division logic
- New
abs
,floor
andceil
functions.
This is a minor version bump as we slowly build our way towards 1.0. Thank you for everyone's support and help as we get there! This has a few notable changes - also introducing a few new interfaces which is the reason for the version bump:
from_parts
function to allow effective creation ofDecimal
's without requiring binary serialization. An example of this benefit is with the lazy static group initializers for Postgres.normalize
function to allow stripping trailing zero's easily.trunc
function allows truncation of a number without any rounding. This effectively "truncates" the fractional part of the number.fract
function returns the fractional part of the number without the integral.- Minor improvements in some iterator logic, utilizing the compiler for further optimizations.
- Fixes issue in string parsing logic whereby
_
would cause numbers to be incorrectly identified. - Many improvements to
mul
. Numbers utilizing thelo
portion of the decimal only will now be shortcut and bigger numbers will now correctly overflow. True overflows will still panic, however large underflows will now be rounded as necessary as opposed to panicing. Hash
was implemented by convention in0.6.5
however is reimplemented explicitly in0.7.0
for effectiveness.- PostgreSQL read performance improved by pre-caching groups and leveraging
normalize
(i.e. avoiding strings). Further optimizations can be made in write however require somediv
optimizations first. - Added short circuit write improvement for zero in PostgreSQL writes.
- Benchmarks are now recorded per build so we can start tracking where slow downs have occurred. This does mean there is a performance hit on Travis builds however hopefully the pay off will make it worthwhile.
Fixes issue with rescale sometimes causing a silent overflow which led to incorrect results during addition, subtraction and compare. Consequently Decimal now rounds the most significant number so that these operations work successfully.
In addition, Decimal now derive's the Hash
trait so that it can be used for indexing.
Fixes silent overflow errors when parsing highly significant strings. from_str
will now round in these scenario's, similar to oleaut32 behavior.
Fixes a regression in ordering where by different scales would be rescaled towards losing precision instead of increasing precision. Have added numerous test suites to help cover more issues like this in the future.
Also fixes an issue in parsing invalid strings whereby the precision exceeded our maximum precision. Previously, this would work with unintended results however this now returns an Error returned from FromStr
.
Fixes an issue with division of rational numbers allowing results greater than MAX_PRECISION
. This would ultimately cause issues for future operations on this number.
In addition, in some cases transitive operations would not be equal due to overflow being lost.
This minor release is purely to expose rust_decimal_macros
for use on the nightly channel. Documentation has been updated accordingly.
This release has a few major changes to the internal workings of the Decimal
implementation and consequently comes with a number of performance improvements.
- Floats can now be parsed into a
Decimal
type usingfrom_f32
andfrom_f64
. add
,sub
,mul
run roughly 1500% faster than before.div
run's roughly 1000% faster than before with room for future improvement.- Also get significant speed improvements with
cmp
,rescale
,round_dp
and some string manipulations. - Implemented
*Assign
traits for simpler usage. - Removed
BigInt
andBigUint
as being intermediary data types.
Minor bug fix to prevent a panic
from overflow during comparison of high significant digit decimals.
Minor bux fix to prevent panic
upon parsing an empty string.
- Removes postgres from default feature set.
bincode
support for serde- Better support for format strings
- Benchmarks added to tests
Fixes bug in cmp
whereby negative's were not being compared correctly.
Minor bug fix to support creating negative numbers using the default constructor.
This release is a stylistic cleanup however does include some minor changes that may break existing builds.
- Serde is now optional. You can enable Serde support within
features
using the keywordserde
. - Serde now returns errors on invalid input as opposed to
0
. f64
conversion support has been added.- Update Postgres dependency to use v0.15.
This is a documentation release that should help with discoverability and usage.