commit_hash
stringlengths
40
40
author
stringlengths
1
57
date
timestamp[s]date
2010-07-26 04:45:09
2026-04-14 18:21:10
message
stringlengths
8
1.39M
diff
stringlengths
68
51.2k
files_changed
int64
1
136
insertions
int64
0
2.35k
deletions
int64
0
1.9k
fad2d4f989a1dd5bebd089b8fcfff53a9adfeee8
Paul Mason
2021-07-28T02:12:40
Minor documentation improvements
diff --git a/src/decimal.rs b/src/decimal.rs index c4103ef..d6ba5c2 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -529,7 +529,7 @@ impl Decimal { /// ``` /// use rust_decimal::Decimal; /// - /// let mut one = Decimal::new(1, 0); + /// let mut one = Decimal::ONE; /// one.set_sign(false); ...
1
14
7
e8727e146f4104c8b54c4ffa6680832c73a95106
Paul Mason
2021-07-21T20:57:50
Fixes linting warning for log10 logic
diff --git a/src/maths.rs b/src/maths.rs index f728670..e6a79b0 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -450,11 +450,7 @@ impl MathematicalOps for Decimal { return Some((result - self.scale()).into()); } - if let Some(result) = self.checked_ln() { - Some(LN10_INVERSE * ...
1
1
5
8c77e271a261efd4ab9e2c61a7c73558b7edd347
Youngchan Lee
2021-07-21T07:14:15
Add test for negative zero serialization
diff --git a/src/serde.rs b/src/serde.rs index 859b5d6..73b1601 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -265,6 +265,14 @@ mod test { assert_eq!("{\"amount\":\"1.234\"}", serialized); } + #[test] + #[cfg(not(feature = "serde-float"))] + fn serialize_negative_zero() { + let record ...
1
8
0
dcb2336d0b091832e11dd675fed2db73f5548074
Youngchan Lee
2021-07-19T04:44:35
Fix negative zero serialization bug
diff --git a/src/str.rs b/src/str.rs index d59d5ed..9b68372 100644 --- a/src/str.rs +++ b/src/str.rs @@ -38,9 +38,13 @@ pub(crate) fn to_str_internal( let len = chars.len(); let whole_len = len - scale; let mut rep = ArrayString::new(); - if append_sign && value.is_sign_negative() { + // Append the...
1
7
3
328ad4696c4c8e78a4db2e8af611cc5c857a924e
Paul Mason
2021-07-21T03:15:52
Round f64 before final conversion in to_f64
diff --git a/src/decimal.rs b/src/decimal.rs index c4103ef..f3c343e 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1841,7 +1841,7 @@ impl ToPrimitive for Decimal { let frac_f64 = (frac_part as f64) / (precision as f64); let value = sign * ((integral_part as f64) + frac_f64); ...
2
4
1
bc0c3638f57aa9b68ccf3851ff6cc5de03025280
James Hinshelwood
2021-07-16T12:15:43
Add tests for decimal roundtripping Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com>
diff --git a/src/serde.rs b/src/serde.rs index 1df545d..859b5d6 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -275,6 +275,32 @@ mod test { assert_eq!("{\"amount\":1.234}", serialized); } + #[test] + #[cfg(all(feature = "serde-float", feature = "serde-arbitrary-precision"))] + fn serialize_dec...
1
26
0
78cab721f3273f517ea2fa57f7aab4c656d29217
James Hinshelwood
2021-07-15T11:17:01
Support serializing to arbitrary precision numbers Closes #402 Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com>
diff --git a/src/serde.rs b/src/serde.rs index b206224..1df545d 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -178,7 +178,7 @@ impl serde::Serialize for Decimal { } } -#[cfg(feature = "serde-float")] +#[cfg(all(feature = "serde-float", not(feature = "serde-arbitrary-precision")))] impl serde::Serialize for D...
1
13
1
9365805c5f2c3cc98d44b486b6ba309e52114a70
Caio
2021-06-08T00:08:19
Update arithmetic.rs My bad. The `?` operator immediately returns the closure so, for example, an input that could spot a bug on the last arithmetic function will never be exercised if the first function returns early.
diff --git a/fuzz/fuzz_targets/arithmetic.rs b/fuzz/fuzz_targets/arithmetic.rs index d009a2c..061f008 100644 --- a/fuzz/fuzz_targets/arithmetic.rs +++ b/fuzz/fuzz_targets/arithmetic.rs @@ -1,6 +1,6 @@ #![no_main] -use rust_decimal::{Decimal, MathematicalOps}; +use rust_decimal::Decimal; #[derive(Debug, arbitrary:...
1
12
17
a231fbf12c543534c6b300648e8c3a8b467968cf
Paul Mason
2021-06-07T18:56:24
Fixes issue with remainder overflow
diff --git a/src/ops/div.rs b/src/ops/div.rs index 948a040..3b5ec57 100644 --- a/src/ops/div.rs +++ b/src/ops/div.rs @@ -196,7 +196,7 @@ impl Buf16 { if num < prod1 { // Detected carry. let tmp = remainder; - remainder += 1; + remainder = rema...
2
10
1
3a4393012c77019a21f05058ad0227afe97f3b12
Paul Mason
2021-05-25T19:05:08
Replace negate with wrapping_neg to prevent overflow
diff --git a/src/ops/add.rs b/src/ops/add.rs index 408ba53..52ba675 100644 --- a/src/ops/add.rs +++ b/src/ops/add.rs @@ -157,7 +157,7 @@ fn aligned_add(lhs: Dec64, rhs: Dec64, negative: bool, scale: u32, subtract: boo fn flip_sign(result: &mut Dec64) { // Bitwise not the high portion result.hi = !result.hi; ...
2
12
14
4b59f535fba75997bcb6e409549eb34797e43ff7
Paul Mason
2021-05-25T05:44:34
Attempt to reproduce #384
diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs index 34c35f3..8975ee3 100644 --- a/tests/decimal_tests.rs +++ b/tests/decimal_tests.rs @@ -3970,3 +3970,25 @@ mod rust_fuzz { assert!(d.is_ok()); } } + +mod issues { + use rust_decimal::prelude::*; + + #[test] + fn issue_384() { + ...
1
22
0
569f5b3b3430a5274c19fad8ec40e2150b2af229
Paul Mason
2021-05-25T04:38:13
Add test for panic conditions
diff --git a/src/maths.rs b/src/maths.rs index 372b241..7bc670c 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -122,7 +122,13 @@ impl MathematicalOps for Decimal { fn exp_with_tolerance(&self, tolerance: Decimal) -> Decimal { match self.checked_exp_with_tolerance(tolerance) { Some(d) => d, -...
2
15
2
b7279d8a60331a91b430cd6ab9dca560b00633d1
Paul Mason
2021-05-25T04:35:17
Add in better logic for negative exp
diff --git a/src/maths.rs b/src/maths.rs index 59b0ed3..372b241 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -83,11 +83,11 @@ pub trait MathematicalOps { fn checked_powf(&self, exp: f64) -> Option<Decimal>; /// Raise self to the given Decimal exponent: x<sup>y</sup>. If `exp` is not whole then the approx...
2
30
22
cbd04a7fa5c822d2313bcaabfea8d66b1cc112a7
Stephen Chung
2021-05-22T06:33:05
Fix checked_exp.
diff --git a/src/maths.rs b/src/maths.rs index 6183f10..59b0ed3 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -53,11 +53,16 @@ pub trait MathematicalOps { /// tolerance of roughly `0.0000002`. Returns `None` on overflow. fn checked_exp(&self) -> Option<Decimal>; + /// The estimated exponential function...
2
48
16
0acadfe68c58453d42a12b14f403d40a60d34d43
Paul Mason
2021-05-21T19:54:15
Use wrapping_sub to address subtraction overflow issue
diff --git a/src/ops/div.rs b/src/ops/div.rs index d302aa1..948a040 100644 --- a/src/ops/div.rs +++ b/src/ops/div.rs @@ -100,11 +100,11 @@ impl Buf16 { // Do a simple check to see if the hi portion of the dividend is greater than the hi // portion of the divisor. let divisor_hi32 = (divisor >...
1
4
4
da5ae18d7671278d69cec13236a53f6351769658
Blas Rodriguez Irizar
2021-05-21T09:29:11
div: update the check to exclude equality Fixes: #376
diff --git a/src/ops/div.rs b/src/ops/div.rs index eb4c606..d302aa1 100644 --- a/src/ops/div.rs +++ b/src/ops/div.rs @@ -100,7 +100,7 @@ impl Buf16 { // Do a simple check to see if the hi portion of the dividend is greater than the hi // portion of the divisor. let divisor_hi32 = (divisor >> ...
2
6
1
b20c229ceca40a99a7a28a237a55de83fbe63aa3
Stephen Chung
2021-05-14T01:07:45
Add checked_add and checked_norm_pdf.
diff --git a/src/maths.rs b/src/maths.rs index af976aa..6183f10 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -49,10 +49,15 @@ pub trait MathematicalOps { /// tolerance of roughly `0.0000002`. fn exp(&self) -> Decimal; + /// The estimated exponential function, e<sup>x</sup>. Stops calculating when it i...
2
36
9
8cc8d695dfc5a17b622be7b1907eb414ababe925
Jeong-Min Lee
2021-05-04T10:25:41
Fix Decimal::MAX comment
diff --git a/src/decimal.rs b/src/decimal.rs index 3f79f51..ce2d9f1 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -30,7 +30,7 @@ const MIN: Decimal = Decimal { hi: 4_294_967_295, }; -/// The smallest value that can be represented by this decimal type. +/// The largest value that can be represented by this...
1
1
1
46b0fdf6a62b28f742b7ec6d24962985d9ebd837
Paul Mason
2021-05-04T01:22:54
Fixes legacy-ops powd calculation test
diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs index 74070b4..749f20c 100644 --- a/tests/decimal_tests.rs +++ b/tests/decimal_tests.rs @@ -3293,9 +3293,17 @@ mod maths { "0.9012", either!("611.04510400020872819829427791", "611.04510400020872819829429407"), ),...
1
10
2
d0645265a243ebf9acb3c7335ef0bc3122702f7f
Paul Mason
2021-05-04T01:17:22
Fixes minor typo in comment
diff --git a/src/maths.rs b/src/maths.rs index 3603f0e..af976aa 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -230,7 +230,7 @@ impl MathematicalOps for Decimal { let exp = exp.normalize(); if exp.scale() == 0 { if exp.mid() != 0 || exp.hi() != 0 { - // Exponent way to big...
1
1
1
50465c49539dbcba7881021ebd71bc12619bd285
Paul Mason
2021-05-04T01:15:32
Fixes negative bases for powd
diff --git a/src/maths.rs b/src/maths.rs index ef22ad8..3603f0e 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -243,12 +243,14 @@ impl MathematicalOps for Decimal { // We do some approximations since we've got a decimal exponent. // For positive bases: a^b = exp(b*ln(a)) - let e = match self...
2
8
3
649efed96f5f9bb4c330c2e10722a7b8a8e7a364
Paul Mason
2021-05-04T01:02:24
Added powx functions to support decimal powers
diff --git a/src/maths.rs b/src/maths.rs index 2d6f9f4..ef22ad8 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -1,31 +1,84 @@ use crate::prelude::*; +use num_traits::pow::Pow; const TWO: Decimal = Decimal::from_parts_raw(2, 0, 0, 0); const PI: Decimal = Decimal::from_parts_raw(1102470953, 185874565, 1703060790, 1...
2
393
122
7f3ec403d1a31e616ec9b1fb9eaed56024e3423e
Paul Mason
2021-05-03T20:58:22
From scientific parsing improvements
diff --git a/src/constants.rs b/src/constants.rs index e77a306..ec62ffe 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -31,6 +31,28 @@ pub const MAX_I128_REPR: i128 = 0x0000_0000_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; pub const POWERS_10: [u32; 10] = [ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 10000000...
5
129
67
704b691f835db9a8902835bff14306ecb38a4544
Paul Mason
2021-05-01T19:50:25
Fixes formatting
diff --git a/src/lib.rs b/src/lib.rs index c452c57..2f524cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,7 +154,7 @@ pub mod prelude { pub use crate::maths::MathematicalOps; pub use crate::{Decimal, RoundingStrategy}; pub use core::str::FromStr; - pub use num_traits::{FromPrimitive, ToPrimitive, Z...
1
1
1
b67a8cb6de2ac91ce04e58b9a38b9a1874de624f
Shane Pearman
2021-05-01T16:38:53
Export num_traits::One from prelude
diff --git a/src/lib.rs b/src/lib.rs index 3302fea..c452c57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,7 +154,7 @@ pub mod prelude { pub use crate::maths::MathematicalOps; pub use crate::{Decimal, RoundingStrategy}; pub use core::str::FromStr; - pub use num_traits::{FromPrimitive, ToPrimitive, Z...
1
1
1
1264ff010ad20dfa61b24ab2453236b0e69b3c28
Paul Mason
2021-04-30T18:31:25
Rename function to try_ and ensure panic message is consistent
diff --git a/src/decimal.rs b/src/decimal.rs index 687858d..6705af9 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -204,7 +204,10 @@ impl Decimal { /// ``` #[must_use] pub fn from_i128_with_scale(num: i128, scale: u32) -> Decimal { - Self::from_i128_with_scale_rslt(num, scale).unwrap() + ...
3
22
10
9b5f427a4644cf4aff34718295722886b1b82c37
jean-airoldie
2021-04-29T20:58:23
Add c-repr feature This adds the c-repr feature which forces `Decimal` to be #[repr(C)]. Closes https://github.com/paupino/rust-decimal/issues/359.
diff --git a/Cargo.toml b/Cargo.toml index 38277cc..6819feb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ serde-str = ["serde"] serde-arbitrary-precision = ["serde", "serde_json/arbitrary_precision"] std = ["arrayvec/std"] tokio-pg = ["db-tokio-postgres"] # Backwards compatability +c-repr = [] # Force D...
3
8
0
73cd8b8b01f328a0ddab059cd9a4d82f7df555e1
Caio
2021-04-30T12:05:38
Unnecessary must_use
diff --git a/src/decimal.rs b/src/decimal.rs index 50f69e1..687858d 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -218,7 +218,6 @@ impl Decimal { /// let max = Decimal::from_i128_with_scale_rslt(i128::MAX, u32::MAX); /// assert!(max.is_err()); /// ``` - #[must_use] pub fn from_i128_with_sca...
1
0
1
65934c43c493cba06ff8bad60b7dd57a599925d7
Caio
2021-04-29T21:09:26
Add `from_i128_with_scale_rslt`
diff --git a/src/decimal.rs b/src/decimal.rs index e05fcf2..50f69e1 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -196,7 +196,7 @@ impl Decimal { /// /// # Example /// - /// ``` + /// ```rust /// use rust_decimal::Decimal; /// /// let pi = Decimal::from_i128_with_scale(3141i128...
4
97
67
010868df104c1b07017e023ec7d98158d03968d0
Paul Mason
2021-04-29T20:43:34
Fixes an issue whereby rounding small negative numbers towards zero would cause negativity to be retained
diff --git a/src/decimal.rs b/src/decimal.rs index b990d44..e05fcf2 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -964,12 +964,7 @@ impl Decimal { RoundingStrategy::RoundDown | RoundingStrategy::ToZero => (), } - Decimal { - lo: value[0], - mid: value[1], - ...
2
18
6
f9e694243d1e8b7fb7b71a0cd0576e5603d43476
Paul Mason
2021-04-24T15:54:44
Added must_use attribute to improve ergonomics
diff --git a/src/decimal.rs b/src/decimal.rs index e0de7b2..b990d44 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -157,6 +157,7 @@ impl Decimal { /// let pi = Decimal::new(3141, 3); /// assert_eq!(pi.to_string(), "3.141"); /// ``` + #[must_use] pub fn new(num: i64, scale: u32) -> Decimal { ...
2
34
2
6779bec5b7c5c06cbc94bbb65f57e732d1c23037
Paul Mason
2021-04-24T14:50:12
Added zero inverse property tests
diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs index 649debd..80a3e31 100644 --- a/tests/decimal_tests.rs +++ b/tests/decimal_tests.rs @@ -283,6 +283,9 @@ fn it_adds_decimals() { let tests = &[ ("0", "0", "0"), + ("0", "-0", "0"), + ("-0", "0", "0"), + ("-0", "-0", "0"...
1
6
0
1b6a708f55a81964b68d3f08ea00dc69d8343ebb
Dmitry Konishchev
2021-04-24T13:19:25
Fix `0 - 0 = -0` -> `0 - 0 = 0`
diff --git a/src/ops/add.rs b/src/ops/add.rs index ddf4ab3..408ba53 100644 --- a/src/ops/add.rs +++ b/src/ops/add.rs @@ -15,7 +15,9 @@ fn add_sub_internal(d1: &Decimal, d2: &Decimal, subtract: bool) -> CalculationRe if d1.is_zero() { // 0 - x or 0 + x let mut result = *d2; - result.set_sig...
2
5
1
42f553fcb70313351459c4ee1d691a22c23e339d
Thom Chiovoloni
2021-04-23T06:12:43
Avoid Error::new in from_scientific except in error cases
diff --git a/src/decimal.rs b/src/decimal.rs index f189ed4..85bdd70 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -329,20 +329,20 @@ impl Decimal { /// assert_eq!(value.to_string(), "0.00000097"); /// ``` pub fn from_scientific(value: &str) -> Result<Decimal, Error> { - let err = Error::new(...
1
5
5
bf094e7de87bd3d3ddeab0b57073676778cfb8df
Paul Mason
2021-04-22T23:58:30
Added todo's for bit shift logic
diff --git a/src/maths.rs b/src/maths.rs index ae05ab6..2d6f9f4 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -163,9 +163,11 @@ impl MathematicalOps for Decimal { if self == &Decimal::ONE { Decimal::ZERO } else { + // TODO: We could just shift left self by 8 h...
1
2
0
e9cef8879a3fb14d224f19e9753186a61c0e095a
Paul Mason
2021-04-22T23:51:58
Fixes sqrt issue by easing up first guess intrinsics
diff --git a/src/maths.rs b/src/maths.rs index f598e08..ae05ab6 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -67,16 +67,16 @@ impl MathematicalOps for Decimal { let mut result = self + Decimal::ONE; let mut prev_result: Option<Decimal> = None; let mut factorial = Decimal::ONE; - let...
2
29
32
9963b6be4cb5e7422c5efbf10f308e4d939e235a
Paul Mason
2021-04-22T22:50:17
Removed UnpackedDecimal usage
diff --git a/src/ops/add.rs b/src/ops/add.rs index b8ecb87..be29bf3 100644 --- a/src/ops/add.rs +++ b/src/ops/add.rs @@ -1,5 +1,5 @@ use crate::decimal::{CalculationResult, Decimal, POWERS_10, SCALE_MASK, SCALE_SHIFT, SIGN_MASK, U32_MASK}; -use crate::ops::common::{Buf24, DecCalc, MAX_I32_SCALE, U32_MAX}; +use crate::...
6
144
110
94ad3d15d7b45043982dbdd7ced7ae56c0c5275a
Paul Mason
2021-04-22T21:45:20
Added u32 optimization branch
diff --git a/src/decimal.rs b/src/decimal.rs index 2698769..f189ed4 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -34,7 +34,7 @@ const U8_MASK: u32 = 0x0000_00FF; pub(crate) const U32_MASK: u64 = 0xFFFF_FFFF; // Number of bits scale is shifted by. -const SCALE_SHIFT: u32 = 16; +pub(crate) const SCALE_SHIFT: u...
3
35
8
c43a7ed99f058f4884863426b7c8e4c5db97728d
Paul Mason
2021-04-22T20:54:14
Deliberate fast_add approach
diff --git a/src/decimal.rs b/src/decimal.rs index 3e7fc9d..2698769 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -23,13 +23,13 @@ use num_traits::{ // Sign mask for the flags field. A value of zero in this bit indicates a // positive Decimal value, and a value of one in this bit indicates a // negative Decima...
3
53
38
3f941fc6058d6ca9a22ca980e977c89f584705b0
Paul Mason
2021-04-22T20:13:44
Replaces std::cmp::Ordering with core::cmp::Ordering
diff --git a/src/ops/div.rs b/src/ops/div.rs index 2a13512..d02708b 100644 --- a/src/ops/div.rs +++ b/src/ops/div.rs @@ -1,9 +1,8 @@ use crate::decimal::{CalculationResult, Decimal, MAX_PRECISION_I32, POWERS_10}; use crate::ops::common::{Buf12, Buf16, DecCalc}; +use core::cmp::Ordering; use core::ops::BitXor; -use...
1
2
3
b2391d22150fd54ba6df32c7c75a12049a5751a9
Paul Mason
2021-04-22T20:03:11
Clippy cleanup
diff --git a/src/decimal.rs b/src/decimal.rs index 40ca906..3e7fc9d 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -83,16 +83,7 @@ const ONE: Decimal = Decimal { // Fast access for 10^n where n is 0-9 pub(crate) const POWERS_10: [u32; 10] = [ - 1, - 10, - 100, - 1_000, - 10_000, - 100_000, - ...
7
80
109
7e52c040e3f065d71dc537f8af8c0e9e142841e4
Paul Mason
2021-04-22T19:32:03
Added micro-optimization to speed up simple add/sub cases
diff --git a/src/decimal.rs b/src/decimal.rs index 9d2f814..40ca906 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1019,6 +1019,26 @@ impl Decimal { } } + #[inline(always)] + pub(crate) const fn lo(&self) -> u32 { + self.lo + } + + #[inline(always)] + pub(crate) const fn mid(...
2
47
0
aacae7be1965fa3d0e13f97d515be926285b32a5
Paul Mason
2021-04-22T18:18:15
Minor cleanup
diff --git a/src/decimal.rs b/src/decimal.rs index 77af0a2..9d2f814 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1019,26 +1019,6 @@ impl Decimal { } } - /// Convert `Decimal` to an internal representation of the underlying struct. This is useful - /// for debugging the internal state of th...
3
18
37
abbb0322f14e19f7555dabdfa7e003c29a34c766
Paul Mason
2021-04-22T17:09:21
Various clean ups around the code base
diff --git a/src/decimal.rs b/src/decimal.rs index 7bc353f..77af0a2 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -2555,9 +2555,9 @@ impl<'a, 'b> Add<&'b Decimal> for &'a Decimal { #[inline(always)] fn add(self, other: &Decimal) -> Decimal { - match self.checked_add(other) { - Some(s...
7
58
63
c5a96d8182fa1668b8b0531f93479e02115a05b8
Paul Mason
2021-04-22T03:56:55
Minor optimizations to add
diff --git a/src/ops/add.rs b/src/ops/add.rs index b785414..3821aa2 100644 --- a/src/ops/add.rs +++ b/src/ops/add.rs @@ -32,52 +32,49 @@ fn add_sub_internal(d1: &Decimal, d2: &Decimal, subtract: bool) -> CalculationRe let mut rescale_factor = d2.scale as i32 - d1.scale as i32; if rescale_factor < 0 { ...
1
40
45
4049055854f34a042f506792ca241da72101cef0
Paul Mason
2021-04-22T03:38:45
Minor optimizations for zero
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index 7c66f25..da2cc5d 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -43,7 +43,7 @@ macro_rules! bench_fold_op { /* Add */ bench_decimal_op!(add_self, +, "2.01", "2.01"); -bench_decimal_op!(add_one_plus_one, +, "1", "1"); +bench_deci...
2
9
11
5d85691f66ba2c814c0072c98f2698c0b136fc14
Paul Mason
2021-04-22T02:34:34
Some further optimizations
diff --git a/src/ops/add.rs b/src/ops/add.rs index b2ce824..ce3e108 100644 --- a/src/ops/add.rs +++ b/src/ops/add.rs @@ -1,5 +1,5 @@ -use crate::decimal::{CalculationResult, Decimal, UnpackedDecimal, POWERS_10, U32_MASK}; -use crate::ops::common::{Buf24, MAX_I32_SCALE}; +use crate::decimal::{CalculationResult, Decimal,...
4
106
79
c4c68781cffea9de0b3a500836c4ad261f79ec50
Paul Mason
2021-04-22T01:55:26
Some micro-optimizations
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index 622b121..7c66f25 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -42,6 +42,8 @@ macro_rules! bench_fold_op { } /* Add */ +bench_decimal_op!(add_self, +, "2.01", "2.01"); +bench_decimal_op!(add_one_plus_one, +, "1", "1"); bench_d...
5
32
30
ba1ca0075ecc4203724dbb7b6ed2f62853c1bf76
Paul Mason
2021-04-21T23:56:38
Fixes change in prelude scope
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index eb452a8..622b121 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -72,6 +72,8 @@ bench_decimal_op!(mul_negative_point_five, *, "2.01", "-0.5"); bench_decimal_op!(mul_pi, *, "2.01", "3.1415926535897932384626433832"); bench_decimal_op...
2
12
10
1075fffc53c572db7e477c93528aa1c6bd58978d
Paul Mason
2021-04-21T23:44:45
Fixes unqualified constant use
diff --git a/src/lib.rs b/src/lib.rs index d722ce6..3f8a213 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,7 +151,7 @@ pub mod prelude { pub use crate::maths::MathematicalOps; pub use crate::{Decimal, RoundingStrategy}; pub use core::str::FromStr; - pub use num_traits::{FromPrimitive, One, ToPrimiti...
2
2
3
3d468347d9a6e71ee833ebc7fdb04029d7532df1
Paul Mason
2021-04-21T23:33:39
Removing some boxing causing regression
diff --git a/src/decimal.rs b/src/decimal.rs index 0529eca..7bc353f 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -49,6 +49,7 @@ pub(crate) const MAX_PRECISION_I32: i32 = 28; // 79,228,162,514,264,337,593,543,950,335 const MAX_I128_REPR: i128 = 0x0000_0000_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; +/// The smallest valu...
7
103
76
87986c1c5ebd5278f19ec709b5f6ab11c0d2ee98
Paul Mason
2021-04-20T17:16:38
Implementation of multiply
diff --git a/src/ops/common.rs b/src/ops/common.rs index 2cc69c7..c240b7a 100644 --- a/src/ops/common.rs +++ b/src/ops/common.rs @@ -1,10 +1,11 @@ -use crate::decimal::Decimal; +use crate::decimal::{CalculationResult, Decimal, MAX_PRECISION, POWERS_10}; // The maximum power of 10 that a 32 bit integer can store pub...
4
207
75
8f3716e38c478a454de78e6c0109fea5eea1af39
Paul Mason
2021-04-20T02:56:13
[no ci] Cleaned up buffers to better represent massive overflow
diff --git a/src/ops/common.rs b/src/ops/common.rs index 44336ea..2cc69c7 100644 --- a/src/ops/common.rs +++ b/src/ops/common.rs @@ -1,4 +1,166 @@ +use crate::decimal::Decimal; + // The maximum power of 10 that a 32 bit integer can store pub const MAX_I32_SCALE: u32 = 9; // The maximum power of 10 that a 64 bit inte...
3
368
226
e531d286fcbbc13a43380203baa16a3c9591e4c6
Caio
2021-04-19T11:43:33
[docs.rs] Enable all-features Some methods vanished from `docs.rs` as they are now optional.
diff --git a/Cargo.toml b/Cargo.toml index 95ea23d..e303df1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,6 @@ tokio-pg = ["db-tokio-postgres"] # Backwards compatability [workspace] members = [".", "./macros"] + +[package.metadata.docs.rs] +all-features = true
1
3
0
9bf9e296ca03def101dd706df8406d4b78f6d24b
Paul Mason
2021-04-16T22:18:37
Exclude generated tests
diff --git a/Cargo.toml b/Cargo.toml index 0c90989..95ea23d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ name = "rust_decimal" readme = "./README.md" repository = "https://github.com/paupino/rust-decimal" version = "1.11.0" +exclude = [ "tests/generated/*" ] [dependencies] arbitrary = { default-fea...
1
1
0
e524da308c7cf6b26bcb313bb60d862724492048
Paul Mason
2021-04-16T20:47:57
Allow reexportable macros via feature flags
diff --git a/macros/Cargo.toml b/macros/Cargo.toml index ded4d0c..4c28eff 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -15,5 +15,9 @@ license = "MIT" rust_decimal = { path = "..", version = "1.10.3" } quote = "1.0" +[features] +default = [] +reexportable = [] + [lib] proc-macro = true diff --git a/ma...
3
62
6
e121013f36969ce31a0effd934c5c4df41c91453
Paul Mason
2021-04-16T19:56:04
Add ability to extract the mantissa of the decimal number
diff --git a/src/decimal.rs b/src/decimal.rs index 6955bfe..0d818b4 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -353,6 +353,26 @@ impl Decimal { ((self.flags & SCALE_MASK) >> SCALE_SHIFT) as u32 } + /// Returns the mantissa of the decimal number. + /// + /// # Example + /// + /// ...
2
34
0
9df3df25dd3cd86b1efa849f7d84b92d6760b3b9
Paul Mason
2021-04-16T19:25:10
NearestEven -> MidpointNearestEven
diff --git a/src/decimal.rs b/src/decimal.rs index eae5b19..6955bfe 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -134,7 +134,7 @@ pub enum RoundingStrategy { /// Also known as "Bankers Rounding". /// e.g. /// 6.5 -> 6, 7.5 -> 8 - NearestEven, + MidpointNearestEven, /// When a number is ...
2
16
16
e8dcfbaa499cb1773fe2b61098c73e89e5097fd8
Paul Mason
2021-04-16T19:22:55
Remove 'midpoint' from top level docs since naming represents midpoint rounding
diff --git a/src/decimal.rs b/src/decimal.rs index 2807ed7..eae5b19 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -126,7 +126,7 @@ pub struct Decimal { mid: u32, } -/// `RoundingStrategy` represents the different midpoint rounding strategies that can be used by +/// `RoundingStrategy` represents the diffe...
1
1
1
e6f78d06ae8a5663af8b282e597b6a1e500eb92c
Paul Mason
2021-04-16T19:17:45
Revamp of RoundingStrategy naming and documentation to make it a bit clearer in regards to functionality
diff --git a/src/decimal.rs b/src/decimal.rs index 4406324..2807ed7 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -126,22 +126,46 @@ pub struct Decimal { mid: u32, } -/// `RoundingStrategy` represents the different strategies that can be used by +/// `RoundingStrategy` represents the different midpoint ro...
2
198
40
7aa26ebe54ff42bf384980f7fccb4e8316511fd2
Paul Mason
2021-04-16T17:50:03
Replace one() with const
diff --git a/src/decimal.rs b/src/decimal.rs index c681e9a..4406324 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -61,6 +61,13 @@ const MAX: Decimal = Decimal { hi: 4_294_967_295, }; +pub(crate) const ONE: Decimal = Decimal { + flags: 0, + lo: 1, + mid: 0, + hi: 0, +}; + // Fast access for 10...
1
11
9
a026ec993b1b0ca51d24e41e58541f7f275d9608
Paul Mason
2021-04-16T17:45:34
Fixed e^-1 incorrectly returning early before calculation had occured
diff --git a/src/maths.rs b/src/maths.rs index 288a870..546d947 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -3,10 +3,11 @@ use crate::prelude::*; const TWO: Decimal = Decimal::from_parts_raw(2, 0, 0, 0); const PI: Decimal = Decimal::from_parts_raw(1102470953, 185874565, 1703060790, 1835008); const LN2: Decimal =...
2
18
23
d864f8d8fd8909e7442eb8fb1749c6a15a604bba
Paul Mason
2021-04-16T16:41:59
Updated from_parts to avoid scale cobbling
diff --git a/src/decimal.rs b/src/decimal.rs index 8fa01d5..c681e9a 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -231,6 +231,13 @@ impl Decimal { /// * `negative` - `true` to indicate a negative number. /// * `scale` - A power of 10 ranging from 0 to 28. /// + /// # Caution: Undefined behavior ...
1
8
1
0bc91cdbe3c07421a3c5ed3e5f0cafa3ca86545f
Paul Mason
2021-04-16T16:10:31
Fixes file formatting
diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs index d3867ae..bd16986 100644 --- a/tests/decimal_tests.rs +++ b/tests/decimal_tests.rs @@ -1942,11 +1942,7 @@ mod maths { 16_u64, Some(Decimal::from_str("65536").unwrap()), ), - ( - Dec...
1
1
5
068f5f7d47e7f6fb37cb7572829cbfe46fed68e1
Paul Mason
2021-04-16T16:07:23
Added checked_powi implementation
diff --git a/src/maths.rs b/src/maths.rs index 0d95f3b..288a870 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -20,6 +20,10 @@ pub trait MathematicalOps { /// Raise self to the given unsigned integer exponent: x<sup>y</sup> fn powi(&self, exp: u64) -> Decimal; + /// Raise self to the given unsigned inte...
2
97
35
c5ab09e820221f26d72aada20470034e868ea01c
teoxoy
2021-03-31T19:41:58
implement num checked traits
diff --git a/src/decimal.rs b/src/decimal.rs index 6c716e5..8fa01d5 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -14,7 +14,9 @@ use diesel::sql_types::Numeric; #[allow(unused_imports)] // It's not actually dead code below, but the compiler thinks it is. #[cfg(not(feature = "std"))] use num_traits::float::Floa...
1
42
5
2638e5ca344c1ea90d4c7687f70eeec715222e35
Paul Mason
2021-03-31T16:07:56
Implements u128/i128 parsing correctly (Fixes #329)
diff --git a/Cargo.toml b/Cargo.toml index bf7bae2..7f2934d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ version = "1.10.3" byteorder = { default-features = false, optional = true, version = "1.3" } bytes = { default-features = false, optional = true, version = "1.0" } diesel = { default-features = fal...
3
95
28
cc7e07851060243ea75b75bb4c43eb2fb4710bb5
Paul Mason
2021-03-09T22:02:34
Finished descale logic, start of alternate scales
diff --git a/src/decimal.rs b/src/decimal.rs index 8cd9680..fdc34af 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -455,7 +455,7 @@ impl Decimal { } /// Deserializes the given bytes into a decimal number. - /// The deserialized byte representation must be 16 bytes and adhere to the followign convent...
1
53
7
2377709833e3ad522d66ca971cd6cf81afc4179a
Paul Mason
2021-03-05T00:46:38
Start of addition impl
diff --git a/src/decimal.rs b/src/decimal.rs index 4e00f7d..8cd9680 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1099,13 +1099,11 @@ impl Decimal { /// Checked subtraction. Computes `self - other`, returning `None` if overflow occurred. #[inline(always)] pub fn checked_sub(self, other: Decimal) -...
1
101
7
e29e2a48ed22776d58924910165d9f9ec5b836ba
Paul Mason
2021-03-04T22:49:27
Move declarative sum tests into public test API
diff --git a/src/decimal.rs b/src/decimal.rs index 2d86515..274f3ef 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -4362,22 +4362,6 @@ mod test { } } - #[test] - fn declarative_dec_sum() { - let vs = (0..10).map(|i| i.into()).collect::<Vec<Decimal>>(); - let sum: Decimal = vs.it...
2
16
16
b7b34aef5a3ad5864f0902cc57c507273f9f7d8a
Paul Mason
2021-03-04T22:36:55
Fixes benchmarks to support mathematics feature flag
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index 213b791..eb452a8 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -218,123 +218,128 @@ fn to_from_sql(b: &mut ::test::Bencher) { }); } -#[bench] -fn powi(b: &mut ::test::Bencher) { - // These exponents have to be fairly sma...
1
118
113
9588662537a33f7832c16acd97be13fcdea7fae6
Paul Mason
2021-02-05T20:52:11
Add in missing overflow for partial 64 divide
diff --git a/src/decimal.rs b/src/decimal.rs index 8829588..e1ef17e 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -2665,7 +2665,7 @@ mod ops { let rem_lo = remainder.lo; remainder.lo = remainder.mid; remainder.mid = remainder.hi; - remainder.hi = 0...
2
8
1
3d6476247e6b03f7c01dc3874ab8c13aece66729
Paul Mason
2021-01-23T16:29:49
Adjust tests to make transitive relationship clearer
diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs index 7d52728..c5b335b 100644 --- a/tests/decimal_tests.rs +++ b/tests/decimal_tests.rs @@ -228,16 +228,16 @@ fn it_negates_decimals() { } let tests = &[ - ("1", "1"), - ("2", "2"), - ("2454495034", "2454495034"), - ("....
1
7
7
69b69e90700be3ad41ae5edbc13f76251fb510bf
Dmitry Konishchev
2021-01-23T12:31:02
Fix a logical error in Neg implementation introduced in #303
diff --git a/src/decimal.rs b/src/decimal.rs index 72fa836..8829588 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -4108,7 +4108,7 @@ impl Neg for Decimal { fn neg(self) -> Decimal { let mut copy = self; - copy.set_sign_negative(true); + copy.set_sign_negative(self.is_sign_positive())...
2
8
7
8a7366daf5b8c3690f19efbb70d1455a21c67a76
Caio
2021-01-20T01:55:53
Fix no-std environment The default features of `arrayvec` assume a std environment
diff --git a/Cargo.toml b/Cargo.toml index ff3791c..6850d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,14 +13,14 @@ version = "1.9.0" [dependencies] byteorder = { default-features = false, optional = true, version = "1.3" } -bytes = { default-features = false, optional = true, version = "1.0.0" } +bytes = { de...
1
5
5
00e56477d9e236a4200f87238b567dd923831dcc
okaneco
2021-01-11T17:36:30
Add TryFrom for f32/f64 to/from Decimal Implement TryFrom<f32/f64> for Decimal Implement TryFrom<Decimal> for f32/f64 Add tests for try_into f64, try_from f32/f64 Fix some clippy lints - Remove unnecessary returns - Remove unnecessary clone on Copy type - Simplify if-chain that returned bool instead of the conditional
diff --git a/src/decimal.rs b/src/decimal.rs index c620762..72fa836 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -654,7 +654,7 @@ impl Decimal { /// ``` pub fn max(self, other: Decimal) -> Decimal { if self < other { - return other; + other } else { ...
2
136
10
5986d6e61b1e74fbcee3808d948c5ed60f3c16e0
Paul Mason
2021-01-09T22:22:04
Fixes subtraction overflow by wrapping
diff --git a/src/decimal.rs b/src/decimal.rs index 2d96953..ecae2e7 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -2306,7 +2306,7 @@ mod division { } let q32 = (temp / divisor64) as u32; self.lo = q32; - ((temp as u32) - q32.wrapping_mul(divisor)) ...
2
7
2
ac2dd78e19a3d9bb48b1591aeb5a5029abede77b
Georgios Konstantopoulos
2020-12-31T20:01:07
feat: tokio 1.0
diff --git a/Cargo.toml b/Cargo.toml index 683dbba..7441cb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,23 +13,23 @@ version = "1.9.0" [dependencies] byteorder = { default-features = false, optional = true, version = "1.3" } -bytes = { default-features = false, optional = true, version = "0.5" } +bytes = { defa...
1
5
5
771eea7556797352593ea0de3f14dafdb97cc45b
Paul Mason
2020-12-30T16:34:59
Refactor to share to_string logic
diff --git a/src/decimal.rs b/src/decimal.rs index c807817..fa480e0 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -3005,6 +3005,16 @@ impl ToPrimitive for Decimal { } } + fn to_i128(&self) -> Option<i128> { + let d = self.trunc(); + let raw: i128 = ((i128::from(d.hi) << 64) | i128...
2
61
95
fc0387a358aaf58fbdf57c220b9b193059717b7e
Paul Mason
2020-12-30T03:37:28
Remove unused function warning
diff --git a/src/decimal.rs b/src/decimal.rs index 5dbaef2..c807817 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -3063,10 +3063,9 @@ impl ToPrimitive for Decimal { } } -// TODO add tests +#[cfg(all(feature = "serde", not(feature = "serde-float")))] impl Decimal { // impl that doesn't allocate for s...
1
1
2
a18af2b32324b6dff3486c58a45856ceb7ebc55f
Paul Mason
2020-12-30T03:24:33
Added additional bench for division
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index 1ee299e..213b791 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -7,10 +7,10 @@ use core::str::FromStr; use rust_decimal::Decimal; macro_rules! bench_decimal_op { - ($name:ident, $op:tt, $y:expr) => { + ($name:ident, $op:tt...
1
31
30
96a4bbb3b883892f9c4df9123a2f3eab7c6b8cce
Paul Mason
2020-12-30T02:58:18
Optimize add_one logic vs add_by logic
diff --git a/src/decimal.rs b/src/decimal.rs index 46a5616..5dbaef2 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -39,8 +39,6 @@ pub(crate) const MAX_PRECISION: u32 = 28; // 79,228,162,514,264,337,593,543,950,335 const MAX_I128_REPR: i128 = 0x0000_0000_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; -const ONE_INTERNAL_REPR: ...
1
50
26
6f21febdf631aef8a2a3b8f290a0e0e626e1129e
Paul Mason
2020-12-30T00:25:17
Added unusued_imports override to silence no_std warnings
diff --git a/src/decimal.rs b/src/decimal.rs index 58e0240..46a5616 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -11,6 +11,7 @@ use core::{ }; #[cfg(feature = "diesel")] use diesel::sql_types::Numeric; +#[allow(unused_imports)] // It's not actually dead code below, but the compiler thinks it is. #[cfg(not(fe...
1
1
0
3a62b867c121a47e0715be16aea9ab7484c3752f
Paul Mason
2020-12-30T00:21:41
Add forbid unsafe to prevent accidental usage
diff --git a/src/lib.rs b/src/lib.rs index d3d5f5d..af53981 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ //! let pi = Decimal::from_parts(1102470952, 185874565, 1703060790, false, 28); //! ``` //! - +#![forbid(unsafe_code)] #![cfg_attr(not(feature = "std"), no_std)] extern crate alloc;
1
1
1
e48e51fe1965e91ded31ca27bb777263f95df042
Paul Mason
2020-12-30T02:38:47
Remove some dead code, small refactor
diff --git a/src/decimal.rs b/src/decimal.rs index 300f551..58e0240 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1676,6 +1676,14 @@ impl Decimal { }; (-self.powi(2) / TWO).exp() / sqrt2pi } + + pub fn from_str_radix(str: &str, radix: u32) -> Result<Self, crate::Error> { + if rad...
2
226
280
4ebd7bb72539f045d6f52624fc724b002c0d6359
jean-airoldie
2020-12-30T01:08:52
Remove the midpoint fix to pass the tests Also adds a reproduction test that was failing in postgres
diff --git a/src/decimal.rs b/src/decimal.rs index 743c155..300f551 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -2496,7 +2496,9 @@ fn parse_str_radix_10(str: &str) -> Result<Decimal, Error> { }; // Round at midpoint - let midpoint = 5; + // FIXME shouldn't this be + //le...
2
8
3
991a2848fc06fdb74d55100f8f7d77563c3deaf9
jean-airoldie
2020-12-30T00:29:59
Fix midpoint calculation error in from_str_radix
diff --git a/src/decimal.rs b/src/decimal.rs index f43090a..743c155 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -2768,7 +2768,7 @@ impl Num for Decimal { }; // Round at midpoint - let midpoint = if radix & 0x1 == 1 { radix / 2 } else { radix + 1 / 2 }; + let mid...
1
2
1
e4a77a6a4fb396c28b654492af405acc982709f7
jean-airoldie
2020-12-29T23:26:40
Run rustfmt
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index 7968b2f..5b3b5fc 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -2,9 +2,9 @@ extern crate test; +use bincode::Options as _; use core::str::FromStr; use rust_decimal::Decimal; -use bincode::Options as _; macro_rules! bench_...
2
2
2
96e3ef4f3d05560ad68c22e80c43795cb7bc07cf
jean-airoldie
2020-12-29T23:11:26
Optimize to_string & from_str impl * Adds arrayvec as a dependency * Removes heap allocations for both serialization & deserialization * Makes the display impl 2 pass instead of 3 pass * Add a specialization for from_str_radix where radix is 10
diff --git a/Cargo.toml b/Cargo.toml index 2db7634..683dbba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ postgres = { default-features = false, optional = true, version = "0.18" } serde = { default-features = false, optional = true, version = "1.0" } serde_json = { default-features = false, optional = t...
3
299
39
eeb5bf410fdede5faa36661a778c860117e0733e
jean-airoldie
2020-12-29T23:02:27
Add serde benches & to_string bench
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index 359424e..7968b2f 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -4,6 +4,7 @@ extern crate test; use core::str::FromStr; use rust_decimal::Decimal; +use bincode::Options as _; macro_rules! bench_decimal_op { ($name:ident,...
1
61
38
c8e70847c101842a71c64eaa69e211f7d0bec539
Paul Mason
2020-12-28T23:30:00
Removes fuzzer project to avoid beginner confusion within the project
diff --git a/Cargo.toml b/Cargo.toml index aa200a4..2db7634 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,4 +43,4 @@ std = [] tokio-pg = ["db-tokio-postgres"] # Backwards compatability [workspace] -members = [".", "./macros", "./fuzzer"] +members = [".", "./macros"] diff --git a/fuzzer/Cargo.toml b/fuzzer/Cargo.t...
4
1
232
da6e59e5c41328b88291b2b6c0257a2f5a17ff68
Paul Mason
2020-12-05T00:38:49
#282: Add i128 and u128 overrides to prevent default trait implementation using u64
diff --git a/src/decimal.rs b/src/decimal.rs index 3b5cb6f..7915764 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -2851,6 +2851,25 @@ impl ToPrimitive for Decimal { Some(value * round_to / round_to) } } + + fn to_i128(&self) -> Option<i128> { + let d = self.trunc(); + l...
2
58
0
264cb0cc312ec7d11cfd84a2a41bd14b6a68c761
Paul Mason
2020-12-04T17:41:58
Fixes serde Formatter sneaking in there
diff --git a/src/decimal.rs b/src/decimal.rs index e021721..2564be3 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -13,7 +13,6 @@ use diesel::sql_types::Numeric; #[cfg(not(feature = "std"))] use num_traits::float::FloatCore; use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero}; -use serde::expor...
1
3
4
df1434635372b48531043122334ac03813053db9
Paul Mason
2020-12-04T16:54:55
#271: Adds Scientific notation formatting to format strings
diff --git a/src/decimal.rs b/src/decimal.rs index 58101ce..e021721 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -13,6 +13,7 @@ use diesel::sql_types::Numeric; #[cfg(not(feature = "std"))] use num_traits::float::FloatCore; use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero}; +use serde::expor...
2
82
0
4bea37518b9aba5f9f351432a77ca6247ce10d97
Paul Mason
2020-11-20T23:01:34
Fixes incompatible non_std tests/code
diff --git a/src/decimal.rs b/src/decimal.rs index 61aa59a..58101ce 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1584,7 +1584,7 @@ impl Decimal { 2 => self * self, _ => { // Square self once and make an infinite sized iterator of the square. - let i = st...
1
11
11
ce9e6195aad18c5dbfb72e695d9c2fd0561ff4c2
Anders429
2020-11-20T01:48:01
Use num_traits::float::FloatCore::powi() in no_std environments.
diff --git a/src/decimal.rs b/src/decimal.rs index e00992b..36cbf29 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -10,6 +10,8 @@ use core::{ }; #[cfg(feature = "diesel")] use diesel::sql_types::Numeric; +#[cfg(not(feature = "std"))] +use num_traits::float::FloatCore; use num_traits::{FromPrimitive, Num, One, ...
1
3
1
5c835b6d54e9ef8ee7f1f8f3c68fcb007370a792
Kyle Leaders
2020-11-17T22:38:46
Optimizing norm_pdf * Cuts time for norm_pdf() by 1/2
diff --git a/src/decimal.rs b/src/decimal.rs index 0d58be7..0a3f181 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1540,27 +1540,8 @@ impl Decimal { /// calculating when it is within tolerance is roughly 0.000002 in order to prevent /// multiplication overflow. pub fn exp(&self) -> Decimal { - ...
1
21
34
8ff9dbb71c58a98a80b0c202cf5794c5f3216171
Kyle Leaders
2020-11-12T23:53:20
Adds exp_with_tolerance()
diff --git a/src/decimal.rs b/src/decimal.rs index 8aa786e..0d58be7 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -1563,6 +1563,34 @@ impl Decimal { result } + /// The estimated exponential function, e<sup>x</sup>, rounded to 8 decimal places. Stops + /// calculating when it is within `toler...
1
67
0
dff0f63946a5fe5f7c6efb0600cb63e8792390c1
Kyle Leaders
2020-11-12T02:31:47
Optimizing Stat functions * Using some reusable constants * More functional `powi` that cuts multiplication in half
diff --git a/src/decimal.rs b/src/decimal.rs index ab6a3d7..8aa786e 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -79,6 +79,27 @@ static BIG_POWERS_10: [u64; 10] = [ 10_000_000_000_000_000_000, ]; +pub const TWO: Decimal = Decimal { + flags: 0, + hi: 0, + lo: 2, + mid: 0, +}; + +pub const PI: ...
1
51
22
2da7c22044595aef0e6b291f23d6964cce93e3fe
Kyle Leaders
2020-11-11T15:48:09
Adding benchmarks for statistical functions
diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs index fe06aec..359424e 100644 --- a/benches/lib_benches.rs +++ b/benches/lib_benches.rs @@ -2,7 +2,6 @@ extern crate test; -use bytes::BytesMut; use core::str::FromStr; use rust_decimal::Decimal; @@ -193,3 +192,124 @@ fn to_from_sql(b: &mut ::test::B...
1
121
1