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 |
|---|---|---|---|---|---|---|---|
62a019d5e97b99284f10b7f676e3a3c55f56e193 | Kyle Leaders | 2020-11-10T19:53:52 | Making statistical functions pub | diff --git a/src/decimal.rs b/src/decimal.rs
index 8070f16..ab6a3d7 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1518,7 +1518,7 @@ impl Decimal {
/// The estimated exponential function, e<sup>x</sup>, rounded to 8 decimal places. Stops
/// calculating when it is within tolerance is roughly 0.000002 in... | 1 | 7 | 7 |
ef658604ac27d0ea0790957276a4c7669060acc1 | Kyle Leaders | 2020-11-02T15:28:37 | Statistical Math functions
Adds support for the following statistical and general math functions:
* powi
* sqrt
* exp (exponential function)
* norm_cdf (cumulative distribution of a normal function)
* norm_pdf (Normal probability density function)
* ln (natural logarithm)
* erf (error function)
I'm definitely not a m... | diff --git a/src/decimal.rs b/src/decimal.rs
index e00992b..8070f16 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1514,6 +1514,122 @@ impl Decimal {
flags: flags(self.is_sign_negative(), quotient_scale),
})
}
+
+ /// The estimated exponential function, e<sup>x</sup>, rounded to 8 de... | 1 | 389 | 0 |
5a05f3b976bdfc59e1137a7fa9f090d6c1234816 | Evgeny Khudoba | 2020-10-18T14:27:34 | formatted | diff --git a/src/decimal.rs b/src/decimal.rs
index 7969f9e..e00992b 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -3170,7 +3170,7 @@ mod test {
#[test]
fn declarative_dec_sum() {
let vs = (0..10).map(|i| i.into()).collect::<Vec<Decimal>>();
- let sum : Decimal = vs.iter().cloned().sum();... | 1 | 2 | 2 |
3a70a0dbafee9217623650c428bb1936804bf7d5 | Evgeny Khudoba | 2020-10-18T14:06:10 | implemented sum trait for immutable reference of decimals | diff --git a/src/decimal.rs b/src/decimal.rs
index fa8e804..7969f9e 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -3048,6 +3048,16 @@ impl Sum for Decimal {
}
}
+impl<'a> Sum<&'a Decimal> for Decimal {
+ fn sum<I: Iterator<Item = &'a Decimal>>(iter: I) -> Self {
+ let mut sum = Decimal::zero();
... | 1 | 26 | 0 |
0ade9c61b41e81d337cc2d5998e9798fb5df96b9 | Paul Mason | 2020-09-15T13:55:35 | Version 1.8.1 | diff --git a/Cargo.toml b/Cargo.toml
index 817075b..f607209 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT"
name = "rust_decimal"
readme = "./README.md"
repository = "https://github.com/paupino/rust-decimal"
-version = "1.8.0"
+version = "1.8.1"
[dependencies]
byteorder = { default-featu... | 3 | 4 | 4 |
8d4c5672c8c3d5aa464f5d05d5e36983ea2d60fd | Paul Mason | 2020-09-14T01:32:47 | Add std feature for proc macro | diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index 26f1a4e..93d7a8c 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -12,7 +12,7 @@ categories = ["science","data-structures"]
license = "MIT"
[dependencies]
-rust_decimal = { path = "..", version = "1.8.0" }
+rust_decimal = { path = "..", version = "1.... | 2 | 1 | 2 |
0f4232c3a7317d4149f486651b6f1af4bd3271e8 | Paul Mason | 2020-09-14T00:59:19 | Version 1.8.0 | diff --git a/Cargo.toml b/Cargo.toml
index 086dee5..c923dca 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT"
name = "rust_decimal"
readme = "./README.md"
repository = "https://github.com/paupino/rust-decimal"
-version = "1.7.0"
+version = "1.8.0"
[dependencies]
byteorder = { default-featu... | 3 | 4 | 4 |
4b70d77b198af76ed8fe0851c3ad224074b21ed2 | Paul Mason | 2020-09-14T00:28:53 | Avoid converting to u128 first, go directly to f64 | diff --git a/src/decimal.rs b/src/decimal.rs
index ee60970..fa8e804 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2663,7 +2663,7 @@ impl ToPrimitive for Decimal {
let frac_part = mantissa % precision;
let frac_f64 = (frac_part as f64) / (precision as f64);
let value = sign ... | 1 | 1 | 1 |
319221f6216ac7c4660547c00cb6d26b720945b5 | Paul Mason | 2020-09-14T00:24:17 | Added rounding before returning from to_f64 | diff --git a/src/decimal.rs b/src/decimal.rs
index a50ab59..ee60970 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2662,7 +2662,9 @@ impl ToPrimitive for Decimal {
let integral_part = mantissa / precision;
let frac_part = mantissa % precision;
let frac_f64 = (frac_part as f6... | 2 | 26 | 34 |
e5ebfa1722d0c0d59c5c224d280f8fddf41cbe86 | Caio | 2020-08-26T20:48:09 | Fix bench build | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 542d5d6..fe06aec 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -2,6 +2,7 @@
extern crate test;
+use bytes::BytesMut;
use core::str::FromStr;
use rust_decimal::Decimal;
@@ -178,15 +179,15 @@ fn to_from_sql(b: &mut ::test::B... | 1 | 6 | 5 |
cad0a9ae7c162ad526089d1022b80fd40726741e | Keith Yeung | 2020-08-02T03:07:19 | Consolidate duplicated zero checks in cmp | diff --git a/src/decimal.rs b/src/decimal.rs
index 1c2041b..794da20 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2991,17 +2991,14 @@ impl PartialOrd for Decimal {
impl Ord for Decimal {
fn cmp(&self, other: &Decimal) -> Ordering {
// Quick exit if major differences
+ if self.is_zero() && o... | 1 | 3 | 6 |
b188c266503198630e0389abbc960668ae5d838f | Sebastian Meßmer | 2020-07-22T21:56:29 | Update decimal.rs | diff --git a/src/decimal.rs b/src/decimal.rs
index 9e76564..1c2041b 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -121,7 +121,7 @@ pub struct Decimal {
/// 1.4999999 -> 1
/// `RoundingStrategy::RoundDown` - Always round down.
/// `RoundingStrategy::RoundUp` - Always round up.
-#[derive(Clone, Copy, PartialEq, ... | 1 | 1 | 1 |
c889de851de52adc3c5a23f0a68fa50304fd719a | Sebastian Meßmer | 2020-07-22T21:53:31 | Derive traits for RoundingStrategy | diff --git a/src/decimal.rs b/src/decimal.rs
index 34ab505..9e76564 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -121,6 +121,7 @@ pub struct Decimal {
/// 1.4999999 -> 1
/// `RoundingStrategy::RoundDown` - Always round down.
/// `RoundingStrategy::RoundUp` - Always round up.
+#[derive(Clone, Copy, PartialEq, ... | 1 | 1 | 0 |
6e341c9dee25c84d57e4b2147a70e6913ffe9474 | Paul Mason | 2020-07-11T19:27:00 | Improve documentation of functions | diff --git a/src/decimal.rs b/src/decimal.rs
index df04a68..34ab505 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -471,13 +471,13 @@ impl Decimal {
self.is_sign_positive()
}
- /// Returns `true` if the decimal is negative.
+ /// Returns `true` if the sign bit of the decimal is negative.
... | 1 | 2 | 2 |
e7e4e0806768331ead16b55b28e9645f5775f1cd | Paul Mason | 2020-07-11T19:18:44 | When value is zero, set scale in early exit | diff --git a/src/decimal.rs b/src/decimal.rs
index 8a9564c..df04a68 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1577,6 +1577,7 @@ fn rescale_internal(value: &mut [u32; 3], value_scale: &mut u32, new_scale: u32)
}
if is_all_zero(value) {
+ *value_scale = new_scale;
return;
}
d... | 2 | 3 | 0 |
aa19fd42abca1f282272b98754ef8959a6a6ad2a | Michał Sieroń | 2020-07-09T13:20:31 | Fixed formatting | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 1a6d854..61bfb82 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -687,11 +687,7 @@ fn it_ceils_decimals() {
#[test]
fn it_finds_max_of_two() {
- let tests = &[
- ("1", "1", "1"),
- ("2", "1", "2"),
- ("1",... | 1 | 2 | 10 |
bf9ed4770d10ac9870f37e7f1839ca3e53062902 | Michał Sieroń | 2020-07-08T16:55:13 | Added `min`, `max` methods similar to the ones `f32` and `f64` have | diff --git a/src/decimal.rs b/src/decimal.rs
index 9b6c6c9..8a9564c 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -619,6 +619,40 @@ impl Decimal {
}
}
+ /// Returns the maximum of the two numbers.
+ ///
+ /// ```
+ /// use rust_decimal::Decimal;
+ ///
+ /// let x = Decimal::new(1... | 2 | 62 | 0 |
c0d14e07a2cf7a41d3fe753b451a2c53fa1d3375 | Paul Mason | 2020-05-20T04:03:20 | Formatting updates | diff --git a/src/decimal.rs b/src/decimal.rs
index 7b44516..9b6c6c9 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2235,7 +2235,7 @@ impl Num for Decimal {
34 => 19,
35 => 19,
36 => 19,
- _ => return Err(Error::new("Unsupported radix"))
+ _ => return Er... | 2 | 14 | 5 |
35b05d2cbf906c99bfed4f843575f5910949fd80 | Paul Mason | 2020-05-20T03:58:26 | Improved radix parsing to support max precision predictions | diff --git a/src/decimal.rs b/src/decimal.rs
index f5680d3..7b44516 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2196,6 +2196,48 @@ impl Num for Decimal {
(b'9', adj + b'a', adj + b'A')
};
+ // Estimate the max precision. All in all, it needs to fit into 96 bits.
+ // Rathe... | 2 | 61 | 10 |
2f73fafec74d1930e728378e5d0cf3422e8ba821 | Paul Mason | 2020-05-20T02:04:33 | Remove blank line | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 93a1dd7..ff67373 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1569,7 +1569,6 @@ fn it_handles_i128_min() {
Decimal::from_i128_with_scale(std::i128::MIN, 0);
}
-
#[test]
fn it_can_rescale() {
let tests = &[
@@ -1592... | 1 | 1 | 2 |
7e058e03fa144a01c12f3bdc24956e690966984c | Paul Mason | 2020-05-20T01:57:58 | Make rescale mutable and updated documentation accordingly | diff --git a/src/decimal.rs b/src/decimal.rs
index c0d1645..f5680d3 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -381,24 +381,38 @@ impl Decimal {
Ok(())
}
- /// Change scale of decimal number, without changing number itself
+ /// Modifies the `Decimal` to the given scale, attempting to do ... | 3 | 71 | 54 |
365f782c6732f00e0ca831231d6236d1448c7304 | serejkaaa512 | 2020-05-19T16:07:10 | refactored old rescale | diff --git a/src/decimal.rs b/src/decimal.rs
index e08a89c..c0d1645 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1035,7 +1035,7 @@ impl Decimal {
let mut my_scale = self.scale();
let mut ot = [other.lo, other.mid, other.hi];
let mut other_scale = other.scale();
- rescale(&mut m... | 1 | 13 | 70 |
a92e80a6ce4542e5b30f2a123865be5a8ccf08d3 | serejkaaa512 | 2020-05-19T14:59:28 | fixed tests | diff --git a/src/postgres.rs b/src/postgres.rs
index 5d79ecd..9a76700 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -237,50 +237,28 @@ mod diesel {
#[test]
fn test_unnecessary_zeroes() {
- let value = Decimal::from_str("0.000001660").unwrap();
- let pg = PgNumeric::from... | 1 | 22 | 44 |
6b2432f4ff073dbfabcc4c702f5d5d56c4b23501 | serejkaaa512 | 2020-05-19T14:32:59 | refactored with_scale | diff --git a/src/decimal.rs b/src/decimal.rs
index ff1b0f8..e08a89c 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -390,32 +390,15 @@ impl Decimal {
/// ```
/// use rust_decimal::Decimal;
///
- /// let number = Decimal::new(1_123, 3).with_scale(6);
+ /// let number = Decimal::new(1_123, 3).res... | 2 | 123 | 92 |
18cef59c4de704ee9d49e121be56d753f847e5be | Paul Mason | 2020-05-19T01:17:36 | Fixes issue whereby string parsing was attempting negative scale | diff --git a/src/decimal.rs b/src/decimal.rs
index 1faeb87..5815206 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -645,10 +645,11 @@ impl Decimal {
/// Returns a new `Decimal` number with the specified number of decimal points for fractional
/// portion.
- /// Rounding is performed using the provid... | 2 | 27 | 3 |
51535c8c51a6c8ab72b38d354e0aaf3537e4b526 | Matthew Tran | 2020-05-17T00:25:04 | Add test for edge case in Decimal::from_i128_with_scale | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index dd32715..3f3eaaa 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1543,3 +1543,9 @@ fn it_computes_equal_hashes_for_positive_and_negative_zero() {
let h2 = hash_it(k2);
assert_eq!(h1, h2);
}
+
+#[test]
+#[should_panic]
+fn... | 1 | 6 | 0 |
94f6446dfc022352b89bb5f38c8f5feb99aa7eff | Matthew Tran | 2020-05-14T22:46:01 | Fix edge case in from_i128_with_scale | diff --git a/src/decimal.rs b/src/decimal.rs
index 706c015..1faeb87 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -34,7 +34,7 @@ const SIGN_SHIFT: u32 = 31;
// The maximum supported precision
const MAX_PRECISION: u32 = 28;
-// 281,474,976,710,655
+// 79,228,162,514,264,337,593,543,950,335
const MAX_I128_REPR... | 1 | 4 | 5 |
b0332047ec7160bbe2331960031a82ee9215dce1 | mfgm2 | 2020-05-16T20:28:31 | Make bytes and byteorder optional | diff --git a/Cargo.toml b/Cargo.toml
index 0932f2f..3fd82a6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,8 +13,8 @@ license = "MIT"
[dependencies]
num-traits = "0.2"
-byteorder = "1.3"
-bytes = "0.5"
+byteorder = { version = "1.3", optional = true }
+bytes = { version = "0.5", optional = true }
diesel = { versi... | 1 | 4 | 3 |
c354b08dec8b36b95fbf5d58fee5ba29f8a30136 | serejkaaa512 | 2020-05-15T08:19:00 | fixed docs | diff --git a/src/decimal.rs b/src/decimal.rs
index 0351b45..4321064 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -384,8 +384,7 @@ impl Decimal {
/// Change scale of decimal number, without changing number itself
///
- /// > Note that values bigger then 28 will cause panic
- /// > Note that sett... | 1 | 1 | 2 |
8ef2f38bc67009cc91d0179d758248f01cde97a5 | serejkaaa512 | 2020-05-14T11:40:20 | improved rounding for last digit in values with scale greater than MAX PRECISION in serialisation / deserialisation | diff --git a/src/decimal.rs b/src/decimal.rs
index 60b7703..0351b45 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -415,7 +415,7 @@ impl Decimal {
result.set_scale(set_scale).unwrap();
result
}
- scale if scale < unpacked.scale => self.round_dp_with_strateg... | 2 | 14 | 8 |
127e28d70cb9a5e658278cda2fb3809cb9aee48f | serejkaaa512 | 2020-05-14T11:06:45 | improved PG deserialise for more than MAX PRECISION | diff --git a/src/decimal.rs b/src/decimal.rs
index 06d77ee..60b7703 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -33,7 +33,7 @@ const SCALE_SHIFT: u32 = 16;
const SIGN_SHIFT: u32 = 31;
// The maximum supported precision
-const MAX_PRECISION: u32 = 28;
+pub(crate) const MAX_PRECISION: u32 = 28;
// 281,474,97... | 2 | 39 | 8 |
f2bc3be98c15b38774dc53a1b94bd2be1ddbb9cb | serejkaaa512 | 2020-05-14T10:39:46 | improved with_scale for MAX PRECISION | diff --git a/src/decimal.rs b/src/decimal.rs
index 0c4990e..06d77ee 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -80,19 +80,6 @@ static BIG_POWERS_10: [u64; 10] = [
1_000_000_000_000_000_000,
10_000_000_000_000_000_000,
];
-// Fast access for 10^n where n is 20-28
-#[allow(dead_code)]
-static MAX_POWE... | 2 | 40 | 16 |
cccf1daff6f7a3ef8b6de3ec8042e30739326f8b | serejkaaa512 | 2020-05-14T09:58:49 | fixed returned from postgres test value | diff --git a/src/postgres.rs b/src/postgres.rs
index 96c7631..50cc90c 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -167,7 +167,7 @@ mod diesel {
scale,
digits: digits.iter().copied().map(|v| v.try_into().unwrap()),
})
- .map_err(Box::new)?)
+ ... | 1 | 4 | 4 |
ac1e409916616983b24838227747dfe21881cfc3 | serejkaaa512 | 2020-05-14T09:43:23 | fixed postgres serialisation, deserialisation of decimal | diff --git a/src/decimal.rs b/src/decimal.rs
index 706c015..0c4990e 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -80,6 +80,19 @@ static BIG_POWERS_10: [u64; 10] = [
1_000_000_000_000_000_000,
10_000_000_000_000_000_000,
];
+// Fast access for 10^n where n is 20-28
+#[allow(dead_code)]
+static MAX_POWE... | 2 | 187 | 114 |
32543a338903466534cd4907cb2b8e989ae2c071 | Paul Mason | 2020-05-07T16:33:24 | Reverse logic for `is_all_zero` check | diff --git a/src/decimal.rs b/src/decimal.rs
index a8f36c5..706c015 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -776,7 +776,7 @@ impl Decimal {
}
}
RoundingStrategy::RoundUp => {
- if is_all_zero(&decimal_portion) {
+ if !is_all_zero(&deci... | 1 | 1 | 1 |
88859f248a6384460baaa823e4ffbecc18c7bb64 | jean-airoldie | 2020-05-07T16:24:48 | Update src/decimal.rs
Co-authored-by: Paul Mason <paul@form1.co.nz> | diff --git a/src/decimal.rs b/src/decimal.rs
index 9df7409..a8f36c5 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -776,7 +776,7 @@ impl Decimal {
}
}
RoundingStrategy::RoundUp => {
- if decimal_portion != [0, 0, 0] {
+ if is_all_zero(&decima... | 1 | 1 | 1 |
83c58517cbb5ff85f1848f0b8a80bc87b5a5675f | jean-airoldie | 2020-05-07T16:05:26 | Added RoundingStrategy::{RoundUp, RoundDown}
The strategy `RoundUp` and `RoundDown` allow the user to unconditionally
round up or down, respectively. | diff --git a/src/decimal.rs b/src/decimal.rs
index ab0b0f0..9df7409 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -119,10 +119,14 @@ pub struct Decimal {
/// `RoundingStrategy::RoundHalfDown` - Rounds down if the value =< 5, otherwise rounds up, e.g.
/// 6.5 -> 6, 6.51 -> 7
/// 1.4999999 -> 1
+/// `RoundingStr... | 2 | 34 | 0 |
2135f71794bd9d361c585464f84f31cfd331ca25 | hengchu | 2020-04-10T02:31:02 | add overflow/underflow tests, and remove float-cmp for now... | diff --git a/Cargo.toml b/Cargo.toml
index 453a39e..7805c1a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,7 +26,6 @@ serde_json = "1.0"
serde_derive = "1.0"
tokio = { version = "0.2", features = ["rt-threaded", "test-util", "macros"] }
futures = "0.3"
-float-cmp = "0.6"
[features]
default = ["serde"]
diff --gi... | 2 | 22 | 7 |
6506553093251ace9db11e9c88d8bfdfa42eaf6d | hengchu | 2020-04-09T17:54:41 | implemented an optimized to_f64() | diff --git a/Cargo.toml b/Cargo.toml
index 7805c1a..453a39e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,6 +26,7 @@ serde_json = "1.0"
serde_derive = "1.0"
tokio = { version = "0.2", features = ["rt-threaded", "test-util", "macros"] }
futures = "0.3"
+float-cmp = "0.6"
[features]
default = ["serde"]
diff --gi... | 3 | 21 | 8 |
644f428d4f8421d1ee2c3102f7bc4314bb883e71 | Paul Mason | 2020-03-23T00:43:59 | Remove std::error::Error providing the description and instead relying on Display | diff --git a/src/postgres.rs b/src/postgres.rs
index f5b94ab..e18c6eb 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -41,15 +41,11 @@ pub struct InvalidDecimal;
impl fmt::Display for InvalidDecimal {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- fmt.write_str(error::Error::description... | 1 | 2 | 6 |
173b80988c89a07686fda10b94d64e4bfe7288bb | Paul Mason | 2020-03-23T00:29:04 | Since inlining, replace is_sign_negative impl with is_sign_positive | diff --git a/src/decimal.rs b/src/decimal.rs
index 5628080..eb5144a 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -352,11 +352,7 @@ impl Decimal {
/// ```
#[inline(always)]
pub fn set_sign_negative(&mut self, negative: bool) {
- if negative {
- self.flags |= SIGN_MASK;
- } ... | 1 | 1 | 5 |
179e64c2378891f456482c32cafe8598a9c18096 | Paul Mason | 2020-03-23T00:24:02 | Deprecate set_sign and replace with set_sign_positive | diff --git a/src/decimal.rs b/src/decimal.rs
index 1dc22ae..5628080 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -306,7 +306,28 @@ impl Decimal {
/// one.set_sign(false);
/// assert_eq!(one.to_string(), "-1");
/// ```
+ #[deprecated(since = "1.4.0", note = "please use `set_sign_positive` instea... | 2 | 50 | 5 |
8ee6b6f6aa000253806224b7708527a2f32060c8 | Paul Mason | 2020-03-23T00:12:16 | Fixes incorrect bit rounding representation for f64 | diff --git a/src/decimal.rs b/src/decimal.rs
index 188b576..1dc22ae 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -914,7 +914,7 @@ impl Decimal {
// floating point number
if is64 {
// Guaranteed to about 16 dp
- while exponent10 < 0 && (bits[2] != 0 || (bits[1] & 0xFFE0_0... | 2 | 4 | 1 |
308659bf5ca7e0b7adacd9c893f677235d8902a0 | Youngchan Lee | 2020-03-04T04:23:57 | Use set_scale() when possible in from_scientific() | diff --git a/src/decimal.rs b/src/decimal.rs
index 9429538..e88dda4 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -256,21 +256,22 @@ impl Decimal {
let mut split = value.splitn(2, |c| c == 'e' || c == 'E');
let base = split.next().ok_or_else(|| err.clone())?;
- let mut scale = split.nex... | 1 | 11 | 10 |
8e55a6265cbc6bfeda2a2e2a221066db3b6b2177 | Youngchan Lee | 2020-03-02T08:16:44 | Add Decimal::from_str() bench | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 1587b88..89e7e70 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -126,6 +126,34 @@ fn iterator_sum(b: &mut ::test::Bencher) {
});
}
+#[bench]
+fn decimal_from_str(b: &mut test::Bencher) {
+ let samples_strs = &[
+ "... | 1 | 28 | 0 |
c8b0b2f6ff1f1218a6aea244c3ba74e25f9f32a8 | Youngchan Lee | 2020-02-25T14:23:23 | Small improvements in Decimal::from_scientific() | diff --git a/src/decimal.rs b/src/decimal.rs
index fef98b5..9429538 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -256,20 +256,19 @@ impl Decimal {
let mut split = value.splitn(2, |c| c == 'e' || c == 'E');
let base = split.next().ok_or_else(|| err.clone())?;
- let mut scale = split.nex... | 1 | 6 | 7 |
5d2627101dc0e9b8eb680217f0a5b2c951bfd83d | Youngchan Lee | 2020-02-25T01:52:36 | Allow scientific notation in dec! macro | diff --git a/macro_impl/src/lib.rs b/macro_impl/src/lib.rs
index c4a8597..c254086 100644
--- a/macro_impl/src/lib.rs
+++ b/macro_impl/src/lib.rs
@@ -20,7 +20,7 @@ pub fn dec(input: TokenStream) -> TokenStream {
source.remove(1);
}
- let decimal = match Decimal::from_str(&source[..]) {
+ let decima... | 2 | 6 | 1 |
a73807d302437cab2ff123b03f62612f58c850d5 | Youngchan Lee | 2020-02-24T09:04:13 | Allow uppercase 'E' in scientific notation | diff --git a/src/decimal.rs b/src/decimal.rs
index bc29165..ce4b9a5 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -253,7 +253,7 @@ impl Decimal {
/// ```
pub fn from_scientific(value: &str) -> Result<Decimal, Error> {
let err = Error::new("Failed to parse");
- let mut split = value.split... | 2 | 2 | 1 |
65102b18a2bf6d7fa8afb00b216896ad80df393d | Paul Mason | 2020-02-23T22:16:14 | Added Signed/Num traits | diff --git a/src/decimal.rs b/src/decimal.rs
index fc71455..188b576 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,6 +1,6 @@
use crate::Error;
-use num_traits::{FromPrimitive, One, ToPrimitive, Zero};
+use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
#[cfg(feature = "diesel")]
use di... | 2 | 226 | 48 |
4c89c1054b1086ee5c90413dc5a4eb2345476217 | Paul Mason | 2020-02-14T01:14:24 | Replace num with num_traits | diff --git a/Cargo.toml b/Cargo.toml
index eb6be9e..7be899b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ categories = ["science","data-structures"]
license = "MIT"
[dependencies]
-num = "0.2"
+num-traits = "0.2"
byteorder = "1.3"
bytes = "0.5"
diesel = { version = "1.4", default-features = false, f... | 6 | 11 | 14 |
f89b818e1a395c2b0ba82dbf8652a9bcd75d0f36 | Paul Mason | 2020-02-04T04:15:41 | Added further tests to cover some rounding checks | diff --git a/src/postgres.rs b/src/postgres.rs
index 8929e8d..c7c945c 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -1,4 +1,4 @@
-use num::{Zero};
+use num::Zero;
use crate::Decimal;
@@ -73,10 +73,11 @@ impl Decimal {
let fixed_scale = scale as i32;
// If we're greater than 8 groups then ... | 1 | 39 | 8 |
63763389e2a904693becf2f6aba2447f2065aeaf | Paul Mason | 2020-02-04T04:01:30 | Added comment and removed debug statement | diff --git a/src/postgres.rs b/src/postgres.rs
index 3641c32..8929e8d 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -71,9 +71,11 @@ impl Decimal {
let mut num_groups = digits.len() as u16;
// Number of digits (in base 10) to print after decimal separator
let fixed_scale = scale as i32... | 1 | 3 | 2 |
0ced473528bb8b79af55bed2736a01229627767f | Paul Mason | 2020-02-04T03:58:13 | Fixes rounding issue when postgres has higher precision than decimal | diff --git a/src/postgres.rs b/src/postgres.rs
index 2b3d3ae..3641c32 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -1,4 +1,4 @@
-use num::Zero;
+use num::{Zero};
use crate::Decimal;
@@ -67,13 +67,21 @@ impl Decimal {
digits,
}: PostgresDecimal<D>,
) -> Result<Self, InvalidDecima... | 1 | 14 | 4 |
d144cf553950bec4fc62edb50c5bc63b97da8124 | Julius de Bruijn | 2020-02-01T10:05:24 | Add another failing test for further fixing | diff --git a/src/postgres.rs b/src/postgres.rs
index 21f1d9e..2b3d3ae 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -609,6 +609,8 @@ mod postgres {
(35, 6, "12340.56789", "12340.567890"),
// Scale is only 28 since that is the maximum we can represent.
(65, 30, "1.2", "1.20... | 1 | 2 | 0 |
b21f116f7d4cf34210e86aea3fded9869a4999e0 | Paul Mason | 2020-01-31T22:13:37 | Added maximum scale support for Postgres module | diff --git a/src/decimal.rs b/src/decimal.rs
index 763986d..bc29165 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -34,6 +34,8 @@ const SIGN_SHIFT: u32 = 31;
// The maximum supported precision
const MAX_PRECISION: u32 = 28;
+// 281,474,976,710,655
+const MAX_I128_REPR: i128 = 0x0000_0000_FFFF_FFFF_FFFF_FFFF_FF... | 2 | 55 | 6 |
1a24bf2159841444971208a54c088f55441bb44d | Julius de Bruijn | 2020-01-31T18:45:16 | Test postgres scale crash | diff --git a/src/postgres.rs b/src/postgres.rs
index 3142f84..0a9dfc6 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -603,6 +603,7 @@ mod postgres {
(35, 6, "1000000", "1000000"),
(35, 6, "9999999.99999", "9999999.999990"),
(35, 6, "12340.56789", "12340.567890"),
+ ... | 1 | 1 | 0 |
44bd0b37b62d9a0d6ddbdcb3eb3db007ba86cfb5 | Shane Hathaway | 2020-01-23T23:54:24 | Normalize -0 as 0.
This was breaking Hash. Test included. | diff --git a/src/decimal.rs b/src/decimal.rs
index 315812b..763986d 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -497,7 +497,7 @@ impl Decimal {
}
}
- /// Strips any trailing zero's from a `Decimal`.
+ /// Strips any trailing zero's from a `Decimal` and converts -0 to 0.
///
/// #... | 2 | 41 | 11 |
f7169cd0d99422e0fc92fb222f8f6c50d4e921d8 | Shane Hathaway | 2020-01-23T21:20:46 | Sort imports to please CI | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 86e9a79..0dd1d86 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1351,8 +1351,8 @@ fn it_computes_equal_hashes_for_equal_values() {
// k1 == k2 -> hash(k1) == hash(k2)"
use std::collections::hash_map::DefaultHasher;
... | 1 | 1 | 1 |
7b20bfc4e1706456418cc36a188c2a73d9677ce1 | Shane Hathaway | 2020-01-23T20:57:01 | Correct formatting and hash calculation in hash test | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index a8e6547..86e9a79 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1372,10 +1372,12 @@ fn it_computes_equal_hashes_for_equal_values() {
let h1 = hash_it(k1);
let h2 = hash_it(k2);
let h3 = hash_it(k3);
+ let h4 = has... | 1 | 3 | 2 |
5701eb82bf07efdfcd06d85cdd043ca5acc99100 | Shane Hathaway | 2020-01-23T20:47:22 | Also verify the hash of "1.01" and "1" are different
Co-Authored-By: Paul Mason <paul@form1.co.nz> | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index c2cc960..a8e6547 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1375,7 +1375,7 @@ fn it_computes_equal_hashes_for_equal_values() {
assert_eq!(h1, h2);
assert_eq!(h1, h3);
-
+assert_ne!(h1, h4);
// Test the applicat... | 1 | 1 | 1 |
5268d667b5646fb6c4eed91df56623c99a0eb841 | Shane Hathaway | 2020-01-23T20:33:01 | Update the non-Diesel Postgres tests to handle trailing zeroes.
Also support an optional POSTGRES_URL environment variable so it's
easy to run tests in different environments. | diff --git a/src/postgres.rs b/src/postgres.rs
index 8fe44c2..3142f84 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -573,37 +573,46 @@ mod postgres {
use std::str::FromStr;
+ /// Gets the URL for connecting to PostgreSQL for testing. Set the POSTGRES_URL
+ /// environment variable to ... | 1 | 36 | 27 |
c493522d2c0288c16f72aa47bd2e364a07fb97a8 | Paul Mason | 2020-01-23T03:56:56 | Remove travis badges | diff --git a/Cargo.toml b/Cargo.toml
index 6aac769..d814f0a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,20 +3,14 @@ name = "rust_decimal"
version = "1.1.0"
authors = ["Paul Mason <paul@form1.co.nz>"]
edition = "2018"
-
description = "A Decimal Implementation written in pure Rust suitable for financial calculatio... | 3 | 0 | 18 |
34c2ccacb008f8f8a447a6b0d01b423bf7b1763f | Paul Mason | 2020-01-23T03:39:27 | Minor formatting changes | diff --git a/src/decimal.rs b/src/decimal.rs
index b220cc6..df504b6 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -185,9 +185,9 @@ impl Decimal {
/// ```
pub const fn from_parts(lo: u32, mid: u32, hi: u32, negative: bool, scale: u32) -> Decimal {
Decimal {
- lo: lo,
- mid:... | 4 | 53 | 41 |
9f788884eac83aadbd87872a1bf44662eb7674ce | Paul Mason | 2020-01-23T02:40:18 | Fixes issue whereby 0 != -0 | diff --git a/src/decimal.rs b/src/decimal.rs
index d054ca7..b220cc6 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2669,8 +2669,14 @@ impl Ord for Decimal {
let self_negative = self.is_sign_negative();
let other_negative = other.is_sign_negative();
if self_negative && !other_negative {
... | 2 | 15 | 0 |
1e193212de06304e1c5e2d4f8f3d4d617677acd4 | Shane Hathaway | 2020-01-22T21:35:45 | Correct hash calculation by normalizing before hashing.
Test included. | diff --git a/src/decimal.rs b/src/decimal.rs
index d054ca7..7a9308b 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2649,10 +2649,11 @@ impl Eq for Decimal {}
impl Hash for Decimal {
fn hash<H: Hasher>(&self, state: &mut H) {
- self.lo.hash(state);
- self.mid.hash(state);
- self.hi.has... | 2 | 62 | 4 |
393a208b22eb7fba063ab1cbdc376ed220468c85 | Shane Hathaway | 2020-01-22T19:29:02 | Retain trailing zeroes received from Postgres. Add tests. | diff --git a/src/postgres.rs b/src/postgres.rs
index e56abfc..4325995 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -91,8 +91,13 @@ impl Decimal {
result *= Decimal::new(10i64.pow((-scale) as u32), 0);
scale = 0;
} else if scale > fixed_scale {
+ // Remove trailing ... | 1 | 29 | 2 |
ac022e7d042e6a98699cee6f0fea946ca9bb422c | Paul Mason | 2019-12-27T02:23:44 | Fixed dependency when using only postgres | diff --git a/src/postgres.rs b/src/postgres.rs
index b432a8d..e56abfc 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -614,6 +614,7 @@ mod postgres {
}
#[tokio::test]
+ #[cfg(feature = "tokio-pg")]
async fn async_test_null() {
use ::tokio_postgres::connect;
... | 1 | 4 | 0 |
d25a27cdb10aad1d520a87d3e40e4bc1fae03178 | Paul Mason | 2019-12-27T02:20:59 | Added tokio-postgres support through tokio-pg | diff --git a/Cargo.toml b/Cargo.toml
index d22f457..7d07a64 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,15 +23,19 @@ byteorder = "1.3"
bytes = "0.5"
diesel = { version = "1.4", default-features = false, features = ["postgres"], optional = true }
postgres = { version = "0.17", optional = true }
+tokio-postgres = ... | 2 | 79 | 0 |
58f1714bc3999aa2f4828ed4bb124ccffb489715 | Paul Mason | 2019-08-23T22:59:57 | Update some syntax to 2018 edition | diff --git a/src/postgres.rs b/src/postgres.rs
index 4459154..ad70ed9 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -2,8 +2,6 @@ use num::Zero;
use crate::Decimal;
-use ::postgres::{to_sql_checked, types::*};
-
use std::{convert::TryInto, error, fmt, result::*};
use crate::decimal::{div_by_u32, is_all_... | 1 | 4 | 6 |
decd294dcd820a153b874db6410fb3c3bcfd307c | Paul Mason | 2019-08-23T20:28:16 | Upgrades rand due to deprecated features | diff --git a/Cargo.toml b/Cargo.toml
index d670fb6..c1d54fb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,7 +24,7 @@ postgres = { version = "0.15", optional = true }
serde = { version = "1.0", optional = true }
[dev-dependencies]
-rand = "0.6"
+rand = "0.7"
serde_json = "1.0"
serde_derive = "1.0"
diff --git a... | 3 | 5 | 5 |
2a1c8686e23f5541b0113becc956f0bd1e2aa3b1 | Dmitry Konishchev | 2019-08-03T08:38:38 | Fix rescaling logic
The rescaling logic has bug where we do rounding. For example the
following program
```rust
use rust_decimal_macros::dec;
fn main() {
let x = dec!(108053.27500000000000000000000);
let y = dec!(0.000000000000000000000000);
let z = x + y;
println!("{} + {} = {}", x, y, z);
}
```
pr... | diff --git a/src/decimal.rs b/src/decimal.rs
index 8e2c6e3..5b443ed 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1375,6 +1375,14 @@ fn rescale(left: &mut [u32; 3], left_scale: &mut u32, right: &mut [u32; 3], righ
return;
}
+ if is_all_zero(left) {
+ *left_scale = *right_scale;
+ ... | 2 | 44 | 5 |
5745595bf9c2624b5ee4ddca0a5c2673a2f0c557 | Filippo Costa | 2019-07-31T14:36:00 | Fix sign flip for PgNumeric -> Decimal conversion | diff --git a/src/postgres.rs b/src/postgres.rs
index 3b691da..4459154 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -181,12 +181,12 @@ mod diesel {
weight,
scale,
ref digits,
- } => (true, weight, scale, digits),
+ } =>... | 1 | 11 | 3 |
70bba88e58654885cb9d40a5850bf17f06a1b880 | Artem Vorotnikov | 2019-05-07T18:38:45 | Diesel support | diff --git a/Cargo.toml b/Cargo.toml
index 7b7e47a..917e186 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ travis-ci = { repository = "paupino/rust-decimal", branch = "master" }
[dependencies]
num = "0.2"
byteorder = "1.3"
+diesel = { version = "1.4", default-features = false, features = ["postgres"], op... | 4 | 536 | 230 |
1eb6040c1dc4a02b96abb86032325b6d7518b8dc | Artem Vorotnikov | 2019-05-07T19:10:53 | Formatted with rustfmt | diff --git a/src/decimal.rs b/src/decimal.rs
index d0020b4..b31b377 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1476,7 +1476,12 @@ impl Decimal {
// Round if necessary. This is for semantic correctness, but could feasibly be removed for
// performance improvements.
if quotient_scale ... | 3 | 44 | 13 |
196cd21b62a1adbfadb4d371672abadc84e4c9cc | Paul Mason | 2019-04-28T21:31:54 | Fixes incorrect equality symbol for calculating weight in ToSql | diff --git a/src/postgres.rs b/src/postgres.rs
index 5563466..4a72835 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -224,7 +224,7 @@ impl ToSql for Decimal {
}
let whole_portion_len = num_groups as isize - fractional_groups_count;
- let weight = if whole_portion_len <= 0 {
+ le... | 1 | 3 | 1 |
35e295c204ca23acdb6e35e91c4043ae78fbfdaf | Paul Mason | 2019-04-28T21:24:44 | Fixes numeric boundaries for Decimal::new() | diff --git a/src/decimal.rs b/src/decimal.rs
index 702b33d..d0020b4 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -110,7 +110,7 @@ pub struct UnpackedDecimal {
/// `Decimal` represents a 128 bit representation of a fixed-precision decimal number.
/// The finite set of values of type `Decimal` are of the form ... | 2 | 18 | 4 |
da0e08080f0d5e9347955aa4ba67f5198ae98514 | Paul Mason | 2019-04-28T21:17:14 | Fixes issues with rem when doing operations with scale | diff --git a/src/decimal.rs b/src/decimal.rs
index 245c008..702b33d 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1458,19 +1458,38 @@ impl Decimal {
return Some(Decimal::zero());
}
+ // Rescale so comparable
+ let initial_scale = self.scale();
+ let mut quotient = [se... | 2 | 29 | 5 |
c29c9b4201deecbbc110eba86df9a68bc9812f10 | Matthew Tran | 2019-04-24T15:49:54 | Implement checked operations | diff --git a/src/decimal.rs b/src/decimal.rs
index 06979b6..245c008 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1056,6 +1056,423 @@ impl Decimal {
flags: flags(!positive, -exponent10 as u32),
})
}
+
+ /// Checked addition. Computes `self + other`, returning `None` if overflow occu... | 1 | 490 | 431 |
3ead59d875b8fa0ec78370a6016340c64b01a722 | Paul Mason | 2019-04-24T04:04:15 | Added further PostgreSQL tests | diff --git a/src/postgres.rs b/src/postgres.rs
index a07419f..5563466 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -264,6 +264,37 @@ mod test {
use std::str::FromStr;
+ pub static TEST_DECIMALS: &[(u32, u32, &str, &str)] = &[
+ // precision, scale, sent, expected
+ (35, 6, "3950.12345... | 1 | 77 | 54 |
ce0802ea9a73ae865546b7ea681d6ae1113fef17 | Paul Mason | 2019-04-24T02:39:02 | Minor updates to dependencies and further cleanups | diff --git a/Cargo.toml b/Cargo.toml
index 3f2c7d1..7fc58ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,13 +19,13 @@ travis-ci = { repository = "paupino/rust-decimal", branch = "master" }
[dependencies]
num = "0.2"
-byteorder = "1.2"
-lazy_static = { version = "1.1", optional = true }
+byteorder = "1.3"
+lazy_s... | 3 | 8 | 4 |
e2b1e0f69ac8e3e5d782b749ebdc751908840131 | Paul Mason | 2019-04-24T02:31:35 | Added better documentation for UnpackedDecimal | diff --git a/src/decimal.rs b/src/decimal.rs
index 0d59375..e080a26 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -850,7 +850,23 @@ impl Decimal {
self.round_dp_with_strategy(dp, RoundingStrategy::BankersRounding)
}
- /// Convert `Decimal` to unpacked representation `UnpackedDecimal`
+ /// C... | 1 | 34 | 2 |
068bc232c94947ce4b658030fac46731073ed5c8 | Paul Mason | 2019-04-07T23:19:52 | Fixes overflow when parsing min values for i32/164 | diff --git a/src/decimal.rs b/src/decimal.rs
index 2091357..0d59375 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1810,16 +1810,16 @@ impl FromStr for Decimal {
impl FromPrimitive for Decimal {
fn from_i32(n: i32) -> Option<Decimal> {
let flags: u32;
- let value_copy: i32;
+ let valu... | 2 | 45 | 8 |
90cad153758dd8083112cbc59a3577b5f142fe26 | jean-airoldie | 2019-03-29T05:04:13 | Use edition 2018 style import | diff --git a/src/decimal.rs b/src/decimal.rs
index e7d86f6..2091357 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,4 +1,3 @@
-
use crate::Error;
use num::{FromPrimitive, One, ToPrimitive, Zero};
diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 74abc3f..eef63be 100644
--- a/tests/decimal_te... | 2 | 4 | 6 |
b4f4b5d1119d7d3922064022f34f9f16bfcf4b6b | jean-airoldie | 2019-03-29T03:51:47 | Added Assignment Operators for references
* Added support for cases where the RHS is a reference.
* Added support for cases where the LHS is a mutable reference.
* Added unit tests for these cases. | diff --git a/src/decimal.rs b/src/decimal.rs
index 32c3503..d68b96c 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,3 +1,4 @@
+
use crate::Error;
use num::{FromPrimitive, One, ToPrimitive, Zero};
@@ -2172,6 +2173,24 @@ impl AddAssign for Decimal {
}
}
+impl<'a> AddAssign<&'a Decimal> for Decimal {
+ ... | 2 | 150 | 0 |
4a52f483843139c2b67449f8fa50cb6ca261636d | jean-airoldie | 2019-03-28T19:30:37 | Added default to decimal | diff --git a/src/decimal.rs b/src/decimal.rs
index 1be3094..0d2c038 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1031,6 +1031,12 @@ impl Decimal {
}
}
+impl Default for Decimal {
+ fn default() -> Self {
+ Self::zero()
+ }
+}
+
#[inline]
#[cfg(feature = "const_fn")]
const fn flags(neg: b... | 1 | 6 | 0 |
167795022b924e5c07c8960e25233d901d969a98 | jean-airoldie | 2019-03-25T22:24:43 | Updated to edition 2018 | diff --git a/Cargo.toml b/Cargo.toml
index fede5c6..bc0cfdb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,7 @@
name = "rust_decimal"
version = "0.11.2"
authors = ["Paul Mason <paul@form1.co.nz>"]
+edition = "2018"
description = "A Decimal Implementation written in pure Rust suitable for financial calculatio... | 16 | 268 | 317 |
2f0fb0ae4151110b31dc6380d16da6212215c669 | jean-airoldie | 2019-03-25T22:24:43 | Add num trait prelude | diff --git a/src/lib.rs b/src/lib.rs
index fef7f8f..120749f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -64,3 +64,7 @@ mod serde_types;
pub use decimal::{Decimal, RoundingStrategy};
pub use error::Error;
+
+pub mod prelude {
+ pub use num::{FromPrimitive, One, ToPrimitive, Zero};
+} | 1 | 4 | 0 |
82bde94bf2726e3e0694d8a19ee9c98eaf66d4e6 | Paul Mason | 2019-03-14T05:52:02 | Added basic sum iterability | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index b3ce633..ec0341b 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -83,6 +83,51 @@ bench_decimal_op!(div_negative_pi, /, "-3.1415926535897932384626433832");
bench_fold_op!(div_10k, /, Decimal::max_value(), 10_000);
+/* Iteration *... | 2 | 75 | 21 |
deeab9a3bf75efc99b47fc8bcfd46b4cf458f496 | Matt Bray | 2019-03-11T21:50:53 | serde: try from_scientific when from_str fails
Allows deserializing strings in scientific notation. | diff --git a/src/serde_types.rs b/src/serde_types.rs
index a07e949..6417c23 100644
--- a/src/serde_types.rs
+++ b/src/serde_types.rs
@@ -50,7 +50,9 @@ impl<'de> serde::de::Visitor<'de> for DecimalVisitor {
where
E: serde::de::Error,
{
- Decimal::from_str(value).map_err(|_| E::invalid_value(Une... | 1 | 4 | 1 |
4de1eee637d3be4935b0c7eae9cab66b1a4a9cab | Marcus Griep | 2018-09-14T17:39:24 | Stabilize, fix postgres build | diff --git a/src/lib.rs b/src/lib.rs
index 4c15fd7..fef7f8f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -35,7 +35,6 @@
//! let pi = Decimal::from_parts(1102470952, 185874565, 1703060790, false, 28);
//! ```
//!
-#![cfg_attr(feature = "const_fn", feature(const_fn))]
extern crate num;
#[cfg(not(feature = "const_fn")... | 2 | 43 | 1 |
f530732ac14f5f83023818f2049c5383e191b6fa | Marcus Griep | 2018-09-14T17:34:43 | Add const_fn
This allows for using the const_fn to build Decimal values at compile-time. | diff --git a/Cargo.toml b/Cargo.toml
index a4e65fc..cf62809 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,7 +19,7 @@ travis-ci = { repository = "paupino/rust-decimal", branch = "master" }
[dependencies]
num = "0.2"
byteorder = "1.2"
-lazy_static = "1.1"
+lazy_static = { version = "1.1", optional = true }
postgres... | 4 | 189 | 13 |
5ebc2052a7a5d848565b06683c8c76cea5448b4c | Ben Barnard | 2018-11-30T19:28:27 | Fix parsing when underscores precede decimal point
Instead of remembering where the number started and how many characters
were seen before the decimal point (and thus incorrectly letting
underscore separator characters affect the scale), just remember how
many coefficients we had parsed when we saw the decimal point. | diff --git a/src/decimal.rs b/src/decimal.rs
index 868420d..f99b035 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1501,8 +1501,7 @@ impl FromStr for Decimal {
}
// should now be at numeric part of the significand
- let mut dot_offset: i32 = -1; // '.' offset, -1 if none
- let cf... | 1 | 7 | 8 |
564abcaf988b8828cf34a2dac3cfa2f66453318c | Ben Barnard | 2018-11-30T19:26:17 | Add failing tests for underscore separator before decimal point
Decimal::from_str sets the scale incorrectly when parsing numbers with
underscore separators before a decimal point, such as "1_234.56",
which gets parsed to a value equivalent to "12345.6". | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index c401788..8a47fcb 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1019,6 +1019,26 @@ fn it_can_parse_fractional_numbers_with_underscore_separators() {
assert_eq!("0.123456", a.to_string());
}
+#[test]
+fn it_can_parse_numbers... | 1 | 20 | 0 |
a5b83071f09a3cf83428987e7c8226c38a7e1d50 | Ben Barnard | 2018-11-30T19:22:47 | Add passing test for parsing fraction with underscores | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 1cae54d..c401788 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -1011,6 +1011,14 @@ fn it_can_parse_alternative_formats() {
}
}
+#[test]
+fn it_can_parse_fractional_numbers_with_underscore_separators() {
+ let a = Decimal... | 1 | 8 | 0 |
3e69db4010ded3808ab7b5983382fc37f087890c | Paul Mason | 2018-11-03T17:45:22 | Fixes bug in string parsing | diff --git a/src/decimal.rs b/src/decimal.rs
index 55d54e9..868420d 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1513,7 +1513,7 @@ impl FromStr for Decimal {
offset += 1;
len -= 1;
- // If the coefficient is longer than 29 then it'll affect the scal... | 2 | 13 | 4 |
9b9fedd049e170ac4bc2fc20dfebf81afa67b57b | Paul Mason | 2018-11-03T17:12:54 | Adds naive rounding for fuzzer | diff --git a/fuzzer/src/command.rs b/fuzzer/src/command.rs
index 6f5764a..559ff1b 100644
--- a/fuzzer/src/command.rs
+++ b/fuzzer/src/command.rs
@@ -6,6 +6,7 @@ use rust_decimal::Decimal;
#[derive(Serialize, Deserialize)]
struct FuzzInput {
+ test: String,
left: String,
right: String,
operator: Op... | 1 | 46 | 15 |
9f310ca6b66125b61d21b52fd63a0eb3855f5c1d | Paul Mason | 2018-11-03T04:45:06 | Minor fixes | diff --git a/fuzzer/src/command.rs b/fuzzer/src/command.rs
index 5d9418f..6f5764a 100644
--- a/fuzzer/src/command.rs
+++ b/fuzzer/src/command.rs
@@ -29,14 +29,21 @@ impl FuzzInput {
let a = d128::from_str(a).unwrap();
let b = d128::from_str(b).unwrap();
- let r = match op {
+ let resul... | 1 | 13 | 5 |
7ab553562d5a0f34e20bd585bdb060bb14c4bb0e | Paul Mason | 2018-11-03T03:58:35 | Fixes issue with parsing highly significant values | diff --git a/fuzzer/Cargo.toml b/fuzzer/Cargo.toml
index 8938711..ff14e99 100644
--- a/fuzzer/Cargo.toml
+++ b/fuzzer/Cargo.toml
@@ -11,7 +11,7 @@ path = "src/main.rs"
clap = "2.32.0"
decimal = "2.0.4"
rand = "0.5"
-rust_decimal = "0.10.1"
+rust_decimal = { path = "../" }
serde = "1.0"
serde_derive = "1.0"
serde_... | 3 | 35 | 11 |
50022a30c2f03831030e65183d4652bd1901a945 | Paul Mason | 2018-08-17T22:52:56 | Update macros to use quote 0.6 as well as output raw format | diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index af90bfc..2dbbbb6 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -18,7 +18,7 @@ travis-ci = { repository = "paupino/rust-decimal", branch = "master" }
[dependencies]
rust_decimal = { path = "../", version = "0.10.1" }
-quote = "0.3"
+quote = "0.6"
... | 4 | 29 | 15 |
93b2cdb5a62936377a61d8981e01713a5b918196 | Paul Mason | 2018-08-15T01:30:43 | Bump dependency versions | diff --git a/Cargo.toml b/Cargo.toml
index 6bfc32f..2f05226 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rust_decimal"
-version = "0.10.0"
+version = "0.10.1"
authors = ["Paul Mason <paul@form1.co.nz>"]
description = "A Decimal Implementation written in pure Rust suitable for financi... | 2 | 6 | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.