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 |
|---|---|---|---|---|---|---|---|
1355ddcc159d8c1765714d058b1f7c45c82f1fde | Andrew Speed | 2018-08-07T20:51:31 | Refactor round_dp_with_strategy tests for RoundHalfDown | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 0800d3e..bc51b11 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -642,73 +642,24 @@ fn it_can_round_complex_numbers_using_round_half_up() {
}
#[test]
-fn it_can_round_zero_using_round_half_down() {
- let a = Decimal::from_str(... | 1 | 18 | 67 |
d9e24ed5147fe0e3e5c70c6b8148cee97135a6b1 | Andrew Speed | 2018-08-07T20:33:48 | Move old_scale initialization before check for scale being less than or equal to decimal places | diff --git a/src/decimal.rs b/src/decimal.rs
index 2e178ce..62fecb3 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -555,14 +555,14 @@ impl Decimal {
};
}
+ let old_scale = self.scale();
+
// return early if decimal has a smaller number of fractional places than dp
/... | 1 | 4 | 4 |
262e44d34861f65e35b7a11e1da7b1f1075dbe75 | Andrew Speed | 2018-07-23T20:54:30 | Refactor round_dp_with_strategy tests for RoundHalfUp | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index 90a657b..0800d3e 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -611,73 +611,24 @@ fn it_can_round_complex_numbers_using_bankers_rounding() {
}
#[test]
-fn it_can_round_zero_using_round_half_up() {
- let a = Decimal::from_str... | 1 | 18 | 67 |
f02220401f7eaa870c29630f188f0587acf7c478 | Andrew Speed | 2018-07-23T20:49:46 | Refactor round_dp_with_strategy tests for BankersRounding | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index b5170a4..90a657b 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -172,12 +172,7 @@ fn it_negates_decimals() {
fn neg(a: &str, b: &str) {
let a = Decimal::from_str(a).unwrap();
let result = -a;
- assert_e... | 1 | 74 | 305 |
9a4b7c9ed6afc51f67171b78230f64287ef53d26 | Andrew Speed | 2018-07-03T20:48:32 | Be explicit when matching on RoundingStrategy | diff --git a/src/decimal.rs b/src/decimal.rs
index 91ebdc5..2e178ce 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -649,7 +649,7 @@ impl Decimal {
_ => {}
}
}
- _ => {
+ RoundingStrategy::RoundHalfUp => {
// when Ordering::Eq... | 1 | 1 | 1 |
241e9227ee843b452261691035cdff1c08142db6 | Andrew Speed | 2018-07-03T20:43:28 | Implement RoundHalfDown | diff --git a/src/decimal.rs b/src/decimal.rs
index 9e7f449..91ebdc5 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -105,10 +105,13 @@ pub struct Decimal {
///
/// `RoundingStrategy::BankersRounding` - Rounds toward the nearest even number, e.g. 6.5 -> 6, 7.5 -> 8
/// `RoundingStrategy::RoundHalfUp` - Rounds up ... | 2 | 93 | 1 |
43b9494787322287e0823e0262db1d5dccd83e4a | Andrew Speed | 2018-06-30T19:02:30 | Add round_dp_with_strategy and implement RoundHalfUp | diff --git a/src/decimal.rs b/src/decimal.rs
index 5b8ca69..9e7f449 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -100,6 +100,17 @@ pub struct Decimal {
mid: u32,
}
+/// `RoundingStrategy` represents the different strategies that can be used by
+/// `round_dp_with_strategy`.
+///
+/// `RoundingStrategy::B... | 3 | 327 | 84 |
6f9fcfc3eeb5ebef2c04b1aaf780c70135004330 | Paul Mason | 2018-07-02T18:15:50 | Fixes minor typo | diff --git a/src/postgres.rs b/src/postgres.rs
index 95fde6e..472410f 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -174,8 +174,8 @@ impl ToSql for Decimal {
let mut mantissa = self.mantissa_array4();
if groups_diff > 0 {
- let reminder = 4 - groups_diff;
- let power = ... | 1 | 2 | 2 |
854d752c09850c2c3ac7df81214552811537660a | Evgeny Khudoba | 2018-07-02T18:06:11 | small changes | diff --git a/src/postgres.rs b/src/postgres.rs
index c6186cd..95fde6e 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -174,8 +174,8 @@ impl ToSql for Decimal {
let mut mantissa = self.mantissa_array4();
if groups_diff > 0 {
- let fractional_group_reminder = 4 - groups_diff;
- ... | 2 | 13 | 7 |
975378aa4c6c2d06f3dae5910e57e1fe6bfe4734 | Evgeny Khudoba | 2018-07-01T04:09:54 | Rewriten method to_sql to avoid string allocations. Speed up almost x4 | diff --git a/src/decimal.rs b/src/decimal.rs
index f631993..5b8ca69 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -637,6 +637,16 @@ impl Decimal {
}
}
+ #[inline(always)]
+ pub(crate) fn mantissa_array3(&self) -> [u32; 3] {
+ [self.lo, self.mid, self.hi]
+ }
+
+ #[inline(always)... | 2 | 47 | 57 |
8a7aedaf951e7fd90d3906474b94c04ba9d299bc | Evgeny Khudoba | 2018-06-30T15:56:25 | added tests&benches for sql | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 1b72119..2a53c52 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -85,6 +85,51 @@ bench_decimal_op!(div_negative_pi, /, "-3.1415926535897932384626433832");
bench_fold_op!(frac_10k, /, Decimal::max_value(), 10_000);
+#[cfg(feature... | 3 | 112 | 41 |
3bd0b148efe762c7047d5693a7c49dd1d60b1e03 | Evgeny Khudoba | 2018-06-27T11:32:52 | Changing `Debug` trait implementation (fixes #126) | diff --git a/src/decimal.rs b/src/decimal.rs
index 9fdf2a7..f631993 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -71,11 +71,22 @@ static BIG_POWERS_10: [u64; 10] = [
10_000_000_000_000_000_000,
];
+/// `UnpackedDecimal` contains unpacked representation of `Decimal` where each component
+/// of decimal-fo... | 1 | 29 | 1 |
356756bc6c1001e2656983033e12d1bd85606e1f | Evgeny Khudoba | 2018-06-24T02:26:41 | accoding to benches inline in this case make speed down | diff --git a/src/decimal.rs b/src/decimal.rs
index fc14cf0..9fdf2a7 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2106,7 +2106,6 @@ forward_all_binop!(impl Div for Decimal, div);
impl<'a, 'b> Div<&'b Decimal> for &'a Decimal {
type Output = Decimal;
- #[inline]
fn div(self, other: &Decimal) -> De... | 1 | 0 | 1 |
74a651248c973eb286fd85935f59c6bd2c8eb081 | Evgeny Khudoba | 2018-06-24T00:03:54 | added frac_10k bench | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 63e8307..1b72119 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -23,7 +23,7 @@ macro_rules! bench_decimal_op {
}
macro_rules! bench_fold_op {
- ($name:ident, $op:tt, $init:expr) => {
+ ($name:ident, $op:tt, $init:expr, $co... | 1 | 6 | 4 |
19829ca80854e08a6170c2ddb8a73fe93670b033 | Evgeny Khudoba | 2018-06-23T20:55:18 | added some test for sub with big mantissa | diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs
index aaa9dd4..afcb3fd 100644
--- a/tests/decimal_tests.rs
+++ b/tests/decimal_tests.rs
@@ -328,6 +328,13 @@ fn it_subtracts_decimals() {
("-3", "2", "-5"),
("1.234", "2.4567", "-1.2227"),
("844.13000000", "843.65000000", "0.4800000... | 1 | 7 | 0 |
56084f855ba51f6bcc9c3305bc5733c7b2f0d0f9 | Evgeny Khudoba | 2018-06-23T19:44:06 | added brackets | diff --git a/src/decimal.rs b/src/decimal.rs
index 83912cc..fc14cf0 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1053,7 +1053,7 @@ fn sub3_internal(value: &mut [u32; 3], by: &[u32; 3]) {
let mut overflow = 0;
let vl = value.len();
for i in 0..vl {
- let part = 0x1_0000_0000u64 + u64::from(... | 1 | 1 | 1 |
011a0a2447c34e0791c2cb4096735e1744f15c08 | Evgeny Khudoba | 2018-06-23T19:28:57 | more compact benches | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 7553503..63e8307 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -22,6 +22,27 @@ macro_rules! bench_decimal_op {
}
}
+macro_rules! bench_fold_op {
+ ($name:ident, $op:tt, $init:expr) => {
+ #[bench]
+ fn $nam... | 1 | 23 | 33 |
e9399d8d86e62b9e86268c718aea779c25e8b44e | Evgeny Khudoba | 2018-06-23T19:01:29 | remove redundancy | diff --git a/src/decimal.rs b/src/decimal.rs
index a368a92..83912cc 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1103,33 +1103,11 @@ fn sub_internal(value: &mut [u32], by: &[u32]) -> u32 {
overflow
}
-//#[inline]
fn sub_part(left: u32, right: u32, overflow: u32) -> (u32, u32) {
let part = 0x1_0000... | 1 | 0 | 22 |
c8917ef3b136886e36a94e68295cbe1f9fbfa763 | Evgeny Khudoba | 2018-06-18T01:24:52 | small improvement on redundant conditional
Signed-off-by: Evgeny Khudoba <evgeny.khudoba.yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index 7c8f1ba..a368a92 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -800,26 +800,18 @@ fn rescale(left: &mut [u32; 3], left_scale: &mut u32, right: &mut [u32; 3], righ
diff -= 1;
}
+ match target {
+ Target::Left => *right_scale = *left_scale... | 1 | 18 | 14 |
69cbc168f9b677bcf4b225959c829632ce36d302 | Evgeny Khudoba | 2018-06-17T23:35:00 | another 20% speed up on bench_dec_10k
Signed-off-by: Evgeny Khudoba <evgeny.khudoba.yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index d881fbf..7c8f1ba 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -766,6 +766,7 @@ fn flags(neg: bool, scale: u32) -> u32 {
/// the maximum scale of left/right. If it is unable to do that it
/// will try to reduce the accuracy of the other argument.
/// e.g. with... | 1 | 1 | 0 |
2c114bfc325095aae76416cbae378859c86b40da | Evgeny Khudoba | 2018-06-17T23:20:24 | gives 20% speed up on bench_dec_10k
Signed-off-by: Evgeny Khudoba <evgeny.khudoba.yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index 4be630a..d881fbf 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -321,6 +321,7 @@ impl Decimal {
}
/// Returns `true` if the decimal is negative.
+ #[inline(always)]
pub fn is_sign_negative(&self) -> bool {
self.flags & SIGN_MASK > 0
... | 1 | 1 | 0 |
91c06dccc25fc51de7ab07070975cf711740b556 | Evgeny Khudoba | 2018-06-17T20:04:06 | simplify sub_internal
Signed-off-by: Evgeny Khudoba <evgeny.khudoba.yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index 9aa555e..4be630a 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1054,6 +1054,18 @@ fn add_part(left: u32, right: u32) -> (u32, u32) {
)
}
+#[inline(always)]
+fn sub3_internal(value: &mut [u32; 3], by: &[u32; 3]) {
+ let mut overflow = 0;
+ let vl = ... | 1 | 43 | 47 |
41a2b4782d7dfe639838c027d19167e4ac18928b | Evgeny Khudoba | 2018-06-17T19:55:28 | added benc_dec_10k
Signed-off-by: Evgeny Khudoba <evgeny.khudoba.yandex.ru> | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 89562cf..7553503 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -32,8 +32,8 @@ bench_decimal_op!(add_pi, +, "3.1415926535897932384626433832");
bench_decimal_op!(add_negative_pi, +, "-3.1415926535897932384626433832");
#[bench]
-f... | 2 | 26 | 6 |
b4782d59122299d6be58c1f535bb44752d06567e | Evgeny Khudoba | 2018-06-16T09:41:08 | improve additional 6% | diff --git a/src/decimal.rs b/src/decimal.rs
index d4a6168..027bfef 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -208,6 +208,7 @@ impl Decimal {
/// let num = Decimal::new(1234, 3);
/// assert_eq!(num.scale(), 3u32);
/// ```
+ #[inline]
pub fn scale(&self) -> u32 {
((self.flags & ... | 1 | 18 | 1 |
69d180a2140e000dce1399f2765848fa05c01efe | Evgeny Khudoba | 2018-06-16T08:10:27 | improve additional 4%
Signed-off-by: Evgeny Khudoba <evgeny.khudoba@yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index 61776c4..d4a6168 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1789,8 +1789,8 @@ impl<'a, 'b> Add<&'b Decimal> for &'a Decimal {
let other_negative = other.is_sign_negative();
let mut negative = false;
let carry;
- if my_negativ... | 1 | 3 | 5 |
f267582e1ad159b076bd501caa4205ced1fbf9fa | Evgeny Khudoba | 2018-06-16T06:20:57 | additional optimization in bench_sum_10m approximately on 16%
Signed-off-by: Evgeny Khudoba <evgeny.khudoba@yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index 496dd85..61776c4 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -899,15 +899,15 @@ fn add_internal(value: &mut [u32], by: &[u32]) -> u32 {
#[inline]
fn add3_internal(value: &mut [u32; 3], by: &[u32; 3]) -> u32 {
- let mut carry: u64 = 0;
+ let mut carry:... | 1 | 6 | 6 |
4fce9c765feaf12e061dfd9c2c582596a61ceb33 | Evgeny Khudoba | 2018-06-05T19:08:46 | optimization in bench_sum_10m almost on 30%
Signed-off-by: Evgeny Khudoba <evgeny.khudoba@yandex.ru> | diff --git a/src/decimal.rs b/src/decimal.rs
index d270683..496dd85 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -897,6 +897,19 @@ fn add_internal(value: &mut [u32], by: &[u32]) -> u32 {
carry as u32
}
+#[inline]
+fn add3_internal(value: &mut [u32; 3], by: &[u32; 3]) -> u32 {
+ let mut carry: u64 = 0;... | 1 | 15 | 2 |
17e3079ac69caa75426630a48b3912c750ab3e20 | Evgeny Khudoba | 2018-06-05T18:40:51 | added sum_10m benchmark
Signed-off-by: Evgeny Khudoba <evgeny.khudoba@yandex.ru> | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index c587b32..89562cf 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -31,6 +31,21 @@ bench_decimal_op!(add_negative_point_five, +, "-0.5");
bench_decimal_op!(add_pi, +, "3.1415926535897932384626433832");
bench_decimal_op!(add_negative_... | 1 | 17 | 2 |
e85f89b655f95cb063b5f74e0e413f2da283c9af | Paul Mason | 2018-05-26T16:55:34 | Fixes nightly tests by declaring feature for proc macro expr | diff --git a/macros/tests/macro_tests.rs b/macros/tests/macro_tests.rs
index d243b1d..8c0088e 100644
--- a/macros/tests/macro_tests.rs
+++ b/macros/tests/macro_tests.rs
@@ -1,3 +1,4 @@
+#![feature(proc_macro_non_items)]
extern crate rust_decimal;
extern crate rust_decimal_macros;
@@ -8,6 +9,6 @@ fn it_can_parse_dec... | 1 | 3 | 2 |
1a8dc6aff62e710eb418eb7847b57aae8faaec25 | Paul Mason | 2018-05-26T00:26:52 | Fixes issue whereby addition underflowed | diff --git a/src/decimal.rs b/src/decimal.rs
index aa5e239..d270683 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1752,7 +1752,7 @@ impl<'a> Neg for &'a Decimal {
lo: self.lo,
mid: self.mid,
}
- }
+ }
}
forward_all_binop!(impl Add for Decimal, add);
@@ -17... | 2 | 39 | 5 |
194e8668a512aa08452396f42e212a890253dc5b | Paul Mason | 2018-04-20T19:19:17 | Removed dependency on interpolate_idents | diff --git a/Cargo.toml b/Cargo.toml
index 0055a54..2213160 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,6 @@ serde = { version = "1.0", optional = true }
decimal = "2.0"
serde_json = "1.0"
serde_derive = "1.0"
-interpolate_idents = "0.2"
[features]
default = ["serde"]
diff --git a/benches/lib_benches.r... | 2 | 73 | 56 |
409ddc1f8bb05af1deaced3b4c61ee6eb2bc64bd | Matthew Plant | 2018-04-17T20:35:58 | Add support for negating decimals | diff --git a/src/decimal.rs b/src/decimal.rs
index f62e162..aa5e239 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -5,7 +5,7 @@ use std::cmp::Ordering::Equal;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::iter::repeat;
-use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Sub, ... | 2 | 48 | 1 |
65c12fb7c39bcf4ac5d6fc7793d8b9783af4eeb8 | Paul Mason | 2018-04-12T19:43:46 | Keep inline in decimal for now | diff --git a/src/decimal.rs b/src/decimal.rs
index 408513b..f62e162 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -754,6 +754,7 @@ impl Decimal {
}
}
+#[inline]
fn flags(neg: bool, scale: u32) -> u32 {
(scale << SCALE_SHIFT) | if neg { SIGN_MASK } else { 0 }
}
@@ -840,6 +841,7 @@ fn rescale(left: &... | 1 | 8 | 0 |
67b080ffdd8d43f5ae80b596a73fa0d6f85234e0 | Paul Mason | 2018-04-12T19:42:22 | Remove release modifiers for perf | diff --git a/Cargo.toml b/Cargo.toml
index 8f3a094..0055a54 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,9 +33,5 @@ interpolate_idents = "0.2"
default = ["serde"]
comparitive = []
-[profile.release]
-debug = true
-lto = false
-
[workspace]
members = [".", "./macros"]
\ No newline at end of file | 1 | 0 | 4 |
e1979ce26a25e56538d1f8c6bd9d8e3c239f8a62 | Paul Mason | 2018-04-12T19:39:58 | Refactor benchmarks to use crate | diff --git a/Cargo.toml b/Cargo.toml
index 5dc0f31..8f3a094 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,18 +24,18 @@ postgres = { version = "0.15", optional = true }
serde = { version = "1.0", optional = true }
[dev-dependencies]
-criterion = "0.2"
decimal = "2.0"
serde_json = "1.0"
serde_derive = "1.0"
+int... | 6 | 93 | 113 |
85ca3a48759f044691934af6affc95a8345fd6e0 | Paul Mason | 2018-04-07T03:39:49 | Fix cargo doc warnings | diff --git a/src/decimal.rs b/src/decimal.rs
index b811251..f62e162 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -72,8 +72,8 @@ static BIG_POWERS_10: [u64; 10] = [
];
/// `Decimal` represents a 128 bit representation of a fixed-precision decimal number.
-/// The finite set of values of type `Decimal` are of ... | 2 | 3 | 18 |
f1ebec44064e1074384ecde576d945121e130c92 | Paul Mason | 2018-04-07T03:29:07 | Added README to RustDocs | diff --git a/src/lib.rs b/src/lib.rs
index ba58143..b9df114 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,55 @@
+//!
+//! A Decimal implementation written in pure Rust suitable
+//! for financial calculations that require significant integral
+//! and fractional digits with no round-off errors.
+//!
+//! The bina... | 1 | 52 | 0 |
25947f4b66992183d4146acc88e222fcec23a69a | Paul Mason | 2018-04-03T18:59:10 | Bump criterion version | diff --git a/Cargo.toml b/Cargo.toml
index e7afee1..b15aeec 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]
-criterion = "0.1.2"
+criterion = "0.2"
decimal = "2.0"
serde_json = "1.0"
serde_... | 1 | 1 | 1 |
18933bd6896fb183f4b5606993484c567a26b424 | Terry Brashaw | 2018-03-24T18:32:06 | Fix panic when formatting precision
Fixes https://github.com/paupino/rust-decimal/issues/113 | diff --git a/src/decimal.rs b/src/decimal.rs
index 6ef978e..740988a 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1650,6 +1650,10 @@ impl fmt::Display for Decimal {
let remainder = div_by_u32(&mut working, 10u32);
chars.push(char::from(b'0' + remainder as u8));
}
+ while... | 2 | 15 | 0 |
23e30b1a505e5031dd7644563ffd0f37dd4e06d3 | Paul Mason | 2018-02-14T04:35:13 | Initial implementation and tests for scientific notation | diff --git a/src/decimal.rs b/src/decimal.rs
index 6ef978e..68fc112 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -158,6 +158,46 @@ impl Decimal {
}
}
+ /// Returns a `Result` which if successful contains the `Decimal` constitution of
+ /// the scientific notation provided by `value`.
+ /... | 2 | 55 | 0 |
ec8a0b82a7b0510f7272fb12d46bb8764637018c | Paul Mason | 2018-02-14T04:13:59 | Fixes issue where by scaling which triggered rounding incorrectly swapped scales | diff --git a/src/decimal.rs b/src/decimal.rs
index 7781281..6ef978e 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -735,7 +735,7 @@ fn rescale(left: &mut [u32; 3], left_scale: &mut u32, right: &mut [u32; 3], righ
Right,
}
- let target;
+ let target; // The target which we're aiming for
l... | 2 | 49 | 16 |
beba416d516d67b7c4268f1617ff85b5aaaa2c8d | Paul Mason | 2018-01-13T16:13:46 | Fixes issue where negative/negative comparisons were incorrect | diff --git a/src/decimal.rs b/src/decimal.rs
index b873162..7781281 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2231,30 +2231,40 @@ impl Ord for Decimal {
// 123 scale 2 and 12345 scale 4
// We need to convert the first to
// 12300 scale 4 so we can compare equally
- let mu... | 2 | 29 | 15 |
f8c1dc6ed9e45ff93666d3c60c49a9e49561d24c | Paul Mason | 2017-12-31T04:59:22 | Added in abs/ceil/floor functions (#105) | diff --git a/src/decimal.rs b/src/decimal.rs
index 376b71f..b873162 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -102,7 +102,9 @@ impl Decimal {
///
/// ```
/// use rust_decimal::Decimal;
- /// let _pi = Decimal::new(3141i64, 3u32);
+ ///
+ /// let pi = Decimal::new(3141, 3);
+ /// ass... | 1 | 143 | 5 |
64ed9c992fa53db85db3697a5378c9cdde80c539 | Paul Mason | 2017-12-31T01:47:49 | Added extra todo comments | diff --git a/src/decimal.rs b/src/decimal.rs
index edbd45e..376b71f 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -747,6 +747,7 @@ fn add_with_scale_internal(
let mut temp3 = [0u32, 0u32, 0u32];
let mut temp4 = [0u32, 0u32, 0u32, 0u32];
if *quotient_scale != *working_scale {
+ // TODO: Remov... | 1 | 3 | 0 |
6d10190ef19353ba90667d5001dfd4241483cd43 | Paul Mason | 2017-12-30T21:51:15 | Minor performance optimization as identified by flame graph | diff --git a/src/decimal.rs b/src/decimal.rs
index c594739..edbd45e 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -744,13 +744,15 @@ fn add_with_scale_internal(
// If our two quotients are different then
// try to scale down the one with the bigger scale
+ let mut temp3 = [0u32, 0u32, 0u32];
+ l... | 1 | 18 | 16 |
395fc2673914766949ca28a84a20daee44f0a82b | Paul Mason | 2017-12-30T21:00:51 | Removed unnessary guard | diff --git a/src/decimal.rs b/src/decimal.rs
index ed46afd..c594739 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -663,15 +663,11 @@ fn rescale(left: &mut [u32; 3], left_scale: &mut u32, right: &mut [u32; 3], righ
// This method should only be used where copy from slice cannot be
#[inline]
fn copy_array_diff_l... | 1 | 4 | 8 |
ab563d255e72a2ac2c446b141192c1b1a5f60e51 | Paul Mason | 2017-12-30T21:00:02 | Removed unncessary comment | diff --git a/src/decimal.rs b/src/decimal.rs
index 0252ca0..ed46afd 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1903,7 +1903,6 @@ impl<'a, 'b> Div<&'b Decimal> for &'a Decimal {
&mut working_quotient,
&mut working_scale,
);
- // TODO: We could round her... | 1 | 0 | 1 |
f6ef51e0befe70c557bcca48bb78e98cb6bbc6a9 | Paul Mason | 2017-12-30T20:57:11 | Further clean up of add_with_scale_internal | diff --git a/src/decimal.rs b/src/decimal.rs
index 03992c8..0252ca0 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -691,24 +691,36 @@ fn add_internal(value: &mut [u32], by: &[u32]) -> u32 {
let mut sum: u64;
for i in 0..bl {
sum = u64::from(value[i]) + u64::from(by[i]) + carry;
- ... | 2 | 66 | 72 |
5a35fe8f694f0353acb07c718d07ea51c0734ebf | Paul Mason | 2017-12-30T19:16:23 | Clean up of division logic | diff --git a/src/decimal.rs b/src/decimal.rs
index f27b410..03992c8 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -317,7 +317,7 @@ impl Decimal {
break;
}
scale -= 1;
- copy_array(&mut result, &working);
+ result.copy_from_slice(&working);
... | 1 | 106 | 163 |
9371618b81812c6a69e40dcafc5a74eda33f5c96 | Paul Mason | 2017-12-30T00:17:06 | Fixes issue whereby _ would skip too much data | diff --git a/src/decimal.rs b/src/decimal.rs
index 296670a..f27b410 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1313,7 +1313,7 @@ impl FromStr for Decimal {
return Err(Error::new("Invalid decimal: must start lead with a number"));
}
offset += 1... | 2 | 28 | 1 |
44164a6090564f0c81223e9f6210e7a62a88e9b8 | Paul Mason | 2017-12-29T23:57:47 | Cleaned up multiplication logic to better align with long mul + added underflow rounding | diff --git a/Cargo.toml b/Cargo.toml
index 3118a3c..89724fa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,6 @@ serde = { version = "1.0", optional = true }
serde_json = "1.0"
serde_derive = "1.0"
decimal = "2.0"
-time = "0.1"
[features]
default = ["serde"]
diff --git a/src/decimal.rs b/src/decimal.rs
ind... | 3 | 187 | 88 |
7a17120c15efd12070a1bde01ed14e92ed8c41e7 | Paul Mason | 2017-12-29T04:53:00 | Various minor loop optimizations | diff --git a/src/decimal.rs b/src/decimal.rs
index 8ff5f59..b09fd3d 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -3,6 +3,7 @@ use num::{FromPrimitive, One, ToPrimitive, Zero};
use std::cmp::*;
use std::cmp::Ordering::Equal;
use std::fmt;
+use std::hash::{Hash, Hasher};
use std::iter::repeat;
use std::ops::{... | 1 | 60 | 51 |
126271f9ef9a1e599bcd55eee70657486be0530f | Paul Mason | 2017-12-29T04:05:17 | Added in pre-calculated groups for postgres | diff --git a/src/decimal.rs b/src/decimal.rs
index 89d5250..8ff5f59 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -128,6 +128,31 @@ impl Decimal {
}
}
+ /// Returns a `Decimal` using the instances constituent parts.
+ ///
+ /// # Arguments
+ ///
+ /// * `lo` - The low 32 bits of a 9... | 2 | 58 | 14 |
98e1189492ecc6dae035029aaf8d1a5244e75a96 | Paul Mason | 2017-12-29T03:18:31 | Shortcircuit the zero case | diff --git a/src/postgres.rs b/src/postgres.rs
index 2c48aab..2ec79c0 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -138,6 +138,12 @@ impl FromSql for Decimal {
impl ToSql for Decimal {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<error::Error + 'static + Sync + Send>> {
+ ... | 1 | 7 | 0 |
de8d5b8735d85223ebedb8651b9d3f7a84670cc7 | Paul Mason | 2017-12-29T02:52:34 | Minor optimization for reading decimals from postgres | diff --git a/src/decimal.rs b/src/decimal.rs
index b070fbe..89d5250 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -277,6 +277,31 @@ impl Decimal {
*self - self.trunc()
}
+ /// Strips any trailing zero's from a `Decimal`. e.g. 1.10 -> 1.1
+ pub fn normalize(&self) -> Decimal {
+ let mu... | 3 | 60 | 21 |
36f751e364389c7d2ab97869d180842eddaef3d1 | Paul Mason | 2017-12-29T02:14:06 | Clean up of rescale logic | diff --git a/src/decimal.rs b/src/decimal.rs
index 9660537..b070fbe 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -550,24 +550,23 @@ fn rescale(left: &mut [u32], left_scale: &mut u32, right: &mut [u32], right_scal
Right,
}
- let target_scale;
- let target_diff;
+ let target;
+ let mut ... | 1 | 12 | 16 |
8b30f4e8c12e24b6831c88e3bfe4d7d826312678 | Paul Mason | 2017-12-29T00:02:54 | Added Hash derive to Decimal | diff --git a/src/decimal.rs b/src/decimal.rs
index a1d9139..b7d1763 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -74,7 +74,7 @@ static BIG_POWERS_10: [u64; 10] = [
/// The finite set of values of type `Decimal` are of the form m / 10^e,
/// where m is an integer such that -2^96 <= m <= 2^96, and e is an intege... | 1 | 1 | 1 |
b3e444f02aa7fc3a4ff2b43471876d604f8d9bb6 | Paul Mason | 2017-12-28T23:54:46 | Fixes use of private function by postgres module | diff --git a/src/postgres.rs b/src/postgres.rs
index 5855f13..ddce4d2 100644
--- a/src/postgres.rs
+++ b/src/postgres.rs
@@ -129,7 +129,7 @@ impl FromSql for Decimal {
if scale > 0 {
let str_rep = result.to_string();
let trailing_zeros = str_rep.chars().rev().take_while(|&x| x == '0')... | 1 | 1 | 1 |
8ea23b9738dc8a52272f94a08921ffead96e050f | Paul Mason | 2017-12-28T23:48:16 | Rust format | diff --git a/src/decimal.rs b/src/decimal.rs
index 9c5c9e5..13318ed 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -300,7 +300,7 @@ impl Decimal {
mid: 0,
hi: 0,
flags: flags(self.is_sign_negative(), dp),
- }
+ };
... | 2 | 64 | 15 |
0fe3c83a53916e1ae8ee7a5a24ac86fe5f46106f | Paul Mason | 2017-12-28T23:46:35 | Refactored rescale to better handle overflow scenarios | diff --git a/src/decimal.rs b/src/decimal.rs
index a1d9139..9c5c9e5 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -240,6 +240,43 @@ impl Decimal {
*MAX
}
+ /// Returns a new `Decimal` integral with no fractional portion.
+ /// This is a true truncation whereby no rounding is performed, e.g. ... | 2 | 263 | 221 |
1a5d7f97c92a09d9c3645e1ab588658e9f0a5914 | Paul Mason | 2017-12-21T21:46:07 | Removes unnecessary working structure | diff --git a/src/decimal.rs b/src/decimal.rs
index f03ff95..34554de 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1198,24 +1198,19 @@ impl FromStr for Decimal {
};
// Parse this using base 10 (future allow using radix?)
- let mut working = [0u32, 0u32, 0u32];
let mut data = [0... | 1 | 1 | 6 |
b1cff44bea9f5ccc714d5508fc1362a8ef910922 | Paul Mason | 2017-12-21T21:27:50 | Rust format application | diff --git a/src/decimal.rs b/src/decimal.rs
index d839f87..5c9f0df 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -209,13 +209,13 @@ impl Decimal {
}
/// Returns `true` if the decimal is negative.
- #[deprecated(since="0.6.3", note="please use `is_sign_negative` instead")]
+ #[deprecated(since =... | 2 | 134 | 36 |
6394f81032f33d420803a2a6ab2dc8c831fda891 | Paul Mason | 2017-12-21T21:27:25 | Implementation of from_str rounding | diff --git a/src/decimal.rs b/src/decimal.rs
index f0231da..d839f87 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1115,6 +1115,49 @@ impl FromStr for Decimal {
coeff.push((b - b'0') as u32);
offset += 1;
len -= 1;
+
+ // If the coe... | 2 | 75 | 14 |
e98415a3ab347d1a5ca0f762463ab16c89bbb5e6 | Paul Mason | 2017-12-21T17:09:42 | Fixes serde deserialization to use input data for type hinting | diff --git a/src/serde_types.rs b/src/serde_types.rs
index 5322602..66383a4 100644
--- a/src/serde_types.rs
+++ b/src/serde_types.rs
@@ -9,7 +9,7 @@ impl<'de> serde::Deserialize<'de> for Decimal {
fn deserialize<D>(deserializer: D) -> Result<Decimal, D::Error>
where
D: serde::de::Deserializer<'de>, {... | 1 | 1 | 1 |
94ac1b1398db9d58d15d7a9a66f3cdd36992d9da | Paul Mason | 2017-11-30T12:06:00 | Deprecate is_negative and is_positive | diff --git a/src/decimal.rs b/src/decimal.rs
index 1f28e1f..f0231da 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -140,7 +140,7 @@ impl Decimal {
/// * `positive`: true if the resulting decimal should be positive.
pub fn set_sign(&mut self, positive: bool) {
if positive {
- if self.i... | 2 | 33 | 21 |
aef63a93bf2bb284ddc4440d94aef439cdd1d42e | Paul Mason | 2017-11-22T15:57:16 | Added simple test suites for common ops with transitive alternatives where appropriate | diff --git a/src/decimal.rs b/src/decimal.rs
index 7d68ea7..1f28e1f 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1136,6 +1136,11 @@ impl FromStr for Decimal {
0
};
+ // If the scale is too big then we could round or error.
+ if scale > MAX_PRECISION {
+ return Er... | 2 | 173 | 422 |
f91bfcba68c6470450c8de040ca18de8c62ed217 | Arkaitz Jimenez | 2017-11-22T11:52:24 | Rescale the one with the smaller scale | diff --git a/src/decimal.rs b/src/decimal.rs
index 16db40b..7d68ea7 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1910,7 +1910,7 @@ impl Ord for Decimal {
return self.lo.cmp(&other.lo);
}
- if self_scale > other_scale {
+ if self_scale < other_scale {
let c = se... | 1 | 1 | 1 |
131240ab4448fede98bfc6c4de355680c24ec4de | Arkaitz Jimenez | 2017-11-22T11:50:48 | Add failing test for ordering | diff --git a/src/decimal.rs b/src/decimal.rs
index e983fb2..16db40b 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -2025,4 +2025,12 @@ mod test {
let b = a.round_dp(2u32);
assert_eq!("1982.27", b.to_string());
}
+
+ #[test]
+ fn ordering() {
+ assert!(Decimal::from_str("0").unwr... | 1 | 8 | 0 |
5722c07cbcbce3eb0f9e09e0e931090eefec97a1 | Paul Mason | 2017-11-22T05:14:27 | Fixes issue with div underflow as well as an issue in mul overflow not recorded | diff --git a/src/decimal.rs b/src/decimal.rs
index a5b557a..e983fb2 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1565,32 +1565,39 @@ impl<'a, 'b> Mul<&'b Decimal> for &'a Decimal {
let mut final_scale = my_scale + ot_scale;
// Do the calculation, this first part is just trying to shortcut cy... | 2 | 111 | 44 |
a517493b773be90fe1272473c0116822cc3a167b | Paul Mason | 2017-11-11T19:25:40 | Added explicit version for macros | diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index ae17c05..1d4b172 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -17,7 +17,7 @@ license = "MIT"
travis-ci = { repository = "paupino/rust-decimal", branch = "master" }
[dependencies]
-rust_decimal = { path = "../" }
+rust_decimal = { path = "../", ve... | 1 | 1 | 1 |
0a602542c23c5e7b2c668dc4c2e3aba7a5185119 | Paul Mason | 2017-11-11T18:58:27 | Flattened directory structure | diff --git a/Cargo.toml b/Cargo.toml
index 421ae3b..cf89f45 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,2 +1,36 @@
+[package]
+name = "rust_decimal"
+version = "0.6.0"
+authors = ["Paul Mason <paul@form1.co.nz>"]
+
+description = "A Decimal Implementation written in pure Rust suitable for financial calculations."
+
... | 12 | 39 | 38 |
45a8c4f4d26b76a7a4e0f86a43f0e793c7cd0988 | Paul Mason | 2017-11-11T06:17:30 | Experimental proc_macro creation | diff --git a/Cargo.toml b/Cargo.toml
index 3d3ff1c..421ae3b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,2 +1,2 @@
[workspace]
-members = ["decimal"]
\ No newline at end of file
+members = ["decimal","decimal_macro"]
\ No newline at end of file
diff --git a/decimal_macro/Cargo.toml b/decimal_macro/Cargo.toml
new fil... | 4 | 49 | 1 |
3eaeeda2cb4d1a349068ef54027b0f6940cf6f97 | Paul Mason | 2017-11-11T05:08:32 | Added test for float deserialization | diff --git a/src/serde_types.rs b/src/serde_types.rs
index ba3c077..5322602 100644
--- a/src/serde_types.rs
+++ b/src/serde_types.rs
@@ -80,6 +80,7 @@ mod test {
let data = [
("{\"amount\":\"1.234\"}", "1.234"),
("{\"amount\":1234}", "1234"),
+ ("{\"amount\":1234.56}", "123... | 1 | 1 | 0 |
fe227a04d37392deafa939f24641268080d9930e | Paul Mason | 2017-11-11T05:05:01 | Clean up remaining biguint decimal references | diff --git a/src/decimal.rs b/src/decimal.rs
index 607e545..a5b557a 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,5 +1,5 @@
use Error;
-use num::{BigUint, FromPrimitive, One, ToPrimitive, Zero};
+use num::{FromPrimitive, One, ToPrimitive, Zero};
use std::cmp::*;
use std::cmp::Ordering::Equal;
use std::fmt;... | 3 | 65 | 128 |
e3006034959115dd3f74d22d0e8972a3f8560adc | Paul Mason | 2017-11-11T04:03:34 | Implemented to_string without biguint | diff --git a/src/decimal.rs b/src/decimal.rs
index 72a47cc..607e545 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1421,7 +1421,13 @@ impl fmt::Display for Decimal {
let mut scale = self.scale() as usize;
// Convert to a string and manipulate that (neg at front, inject decimal)
- let mu... | 1 | 7 | 1 |
5477581bf8a14887e440e6e389ae6d3e21c7f4fd | Paul Mason | 2017-11-11T02:51:58 | Removed bigint from from_str | diff --git a/src/decimal.rs b/src/decimal.rs
index 6b35652..72a47cc 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1140,15 +1140,15 @@ impl FromStr for Decimal {
let mut offset = 0;
let mut len = value.len();
- let chars: Vec<char> = value.chars().collect();
+ let bytes: Vec<u8> ... | 1 | 47 | 34 |
49dde6e830eb235a7a1d1e6b4c26f09c9fe9e482 | Paul Mason | 2017-11-11T01:51:31 | Added back pub(crate) to rescale for postgres | diff --git a/src/decimal.rs b/src/decimal.rs
index 5a18d25..6b35652 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -306,7 +306,7 @@ impl Decimal {
}
}
- fn rescale(&self, exp: u32) -> Decimal {
+ pub(crate) fn rescale(&self, exp: u32) -> Decimal {
if exp > MAX_PRECISION {
... | 1 | 1 | 1 |
26d2701d6f5c5f0db58c2c61a22b615f9e7863de | Paul Mason | 2017-11-11T01:46:21 | Remove benchmark test | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index f53de0d..20afff1 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -39,16 +39,3 @@ bench_bin_op!(bench_d128_mul, d128, *=);
bench_bin_op!(bench_decimal_div, Decimal, /=);
bench_bin_op!(bench_d128_div, d128, /=);
-
-#[bench]
-fn ben... | 1 | 0 | 13 |
d3e43406b56092e46002fdd9e1740ff5ca751548 | Paul Mason | 2017-11-11T01:02:47 | minor conversion optimizations | diff --git a/src/decimal.rs b/src/decimal.rs
index 89ddaa9..5a18d25 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,6 +1,5 @@
use Error;
-use num::{BigInt, BigUint, FromPrimitive, One, ToPrimitive, Zero};
-use num::bigint::Sign::{Minus, Plus};
+use num::{BigUint, FromPrimitive, One, ToPrimitive, Zero};
use std... | 2 | 58 | 19 |
118c1a1eef78ef85305b036679df27e12fe8e579 | Paul Mason | 2017-11-11T00:38:35 | Update rouding to avoid biguint | diff --git a/src/decimal.rs b/src/decimal.rs
index f0656a0..89ddaa9 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -266,30 +266,34 @@ impl Decimal {
}
}
- // Do some midpoint rounding checks
+ // Do some midpoint rounding checks
// We'r... | 1 | 16 | 12 |
eb6958442a48b0cbe064e4d965815d2651033353 | Paul Mason | 2017-11-11T00:35:49 | Minor refactor of round_up to get rid of various conversions | diff --git a/Cargo.toml b/Cargo.toml
index d71dec7..63a4252 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,6 +27,7 @@ serde = { version = "1.0", optional = true }
serde_json = "1.0"
serde_derive = "1.0"
decimal = "2.0"
+time = "0.1"
[features]
default = ["serde"]
\ No newline at end of file
diff --git a/benches... | 4 | 122 | 72 |
5b0a8b628b2e3b091087c0f46103017d5847f8bf | Paul Mason | 2017-11-10T21:29:23 | implemented basic assign traits | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 18c7f12..1a4270a 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -18,7 +18,7 @@ macro_rules! bench_bin_op {
for _ in 0..100 {
let mut x = y;
for _ in 0..50 {
- ... | 3 | 100 | 10 |
de251662bd848dea96ab32b5784bd91d107f5ee9 | Paul Mason | 2017-11-10T21:05:25 | Minor formatting | diff --git a/src/decimal.rs b/src/decimal.rs
index 2850d4b..d05c9b2 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -12,7 +12,6 @@ use std::str::FromStr;
// 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 Dec... | 1 | 79 | 35 |
e3de6caf60512ae16199c51b7e2c57f4d4e9a35c | Paul Mason | 2017-11-10T20:08:48 | Some further cleanup | diff --git a/src/decimal.rs b/src/decimal.rs
index df6b77c..9485e0e 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -985,9 +985,8 @@ fn is_all_zero(bits: &[u32]) -> bool {
true
}
-fn is_some_zero(bits: &[u32], start: usize, end: usize) -> bool {
- assert!(end > start);
- for b in bits.iter().skip(star... | 1 | 5 | 6 |
f0b1af4e2d0f0087b21ef87c4336a5b2e424be5c | Paul Mason | 2017-11-10T20:05:54 | Minor cleanups | diff --git a/src/decimal.rs b/src/decimal.rs
index 57fd190..df6b77c 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -552,8 +552,16 @@ fn power_10(exponent: usize) -> BigUint {
}
}
-fn copy_array(into: &mut [u32], from: &[u32], max: usize) {
- let limit = from.len().min(max);
+fn copy_array(into: &mut [u3... | 1 | 32 | 21 |
95d33d00db30089d5af10fb8bf5f99edbb762439 | Arkaitz Jimenez | 2017-11-10T20:00:57 | Speed up same scale comparison | diff --git a/src/decimal.rs b/src/decimal.rs
index a4b0b51..604cbb9 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -99,7 +99,7 @@ impl Decimal {
/// ```
pub fn new(num: i64, scale: u32) -> Decimal {
if scale > MAX_PRECISION {
- panic!("Scale exceeds the maximum precision allowed");
+ ... | 1 | 17 | 9 |
343f57f4c65963d2a56acafe649a764258ca907f | Paul Mason | 2017-11-10T19:47:10 | Start of refactoring to ensure reusability | diff --git a/src/decimal.rs b/src/decimal.rs
index c0481d8..57fd190 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -301,7 +301,7 @@ impl Decimal {
let result: BigUint;
// Figure out whether to multiply or divide
- let power = Decimal::power_10(diff.abs() as usize);
+ let power = p... | 1 | 486 | 518 |
3475ddb3736753c7af53a4321f9c9c30d40aa643 | Paul Mason | 2017-11-08T20:13:14 | Leverage div_internal for rem calcs | diff --git a/src/decimal.rs b/src/decimal.rs
index e9b17f0..c0481d8 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1771,18 +1771,21 @@ impl<'a, 'b> Rem<&'b Decimal> for &'a Decimal {
if self.is_zero() {
return Decimal::zero();
}
-/*
- // Make sure they're scaled
- let ... | 1 | 15 | 12 |
a0458ec2869aadf2dee1651fbb9698b6a5b42055 | Paul Mason | 2017-11-08T20:04:51 | Fixes bug in add with scale where remainder wasn't added | diff --git a/src/decimal.rs b/src/decimal.rs
index 704da01..e9b17f0 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -335,11 +335,13 @@ impl Decimal {
carry as u32
}
- fn add_internal_lossy(quotient: &mut [u32; 3], quotient_scale: &mut i32, working: &mut [u32; 8], working_scale: &mut i32) -> bool ... | 2 | 25 | 63 |
b01f460e39bf1d7a41847d5060db6145bfcfa591 | Paul Mason | 2017-11-08T16:24:57 | Added further debugging before refactor | diff --git a/src/decimal.rs b/src/decimal.rs
index 918f6a8..704da01 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -216,7 +216,7 @@ impl Decimal {
let old_scale = self.scale();
- // We artificially cap at 20 because of fast power lookup.
+ // We artificially cap at 20 because of fast po... | 1 | 45 | 34 |
e52d7ef4461d61e4160bf7de7d0be4a7f134a923 | Paul Mason | 2017-11-08T00:05:42 | Attemting refactor to identify bug in algorithm | diff --git a/src/decimal.rs b/src/decimal.rs
index 5fcccfe..918f6a8 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -216,8 +216,9 @@ impl Decimal {
let old_scale = self.scale();
+ // We artificially cap at 20 because of fast power lookup.
+ // We should change this as it's not necessary.... | 1 | 247 | 219 |
ce0fa93c781fbc29a89c34c79765955068f3078c | Paul Mason | 2017-11-06T15:59:12 | Initial (buggy and ineffective) impl of div | diff --git a/src/decimal.rs b/src/decimal.rs
index a4b0b51..5fcccfe 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,5 +1,5 @@
use Error;
-use num::{BigInt, BigUint, FromPrimitive, Integer, One, ToPrimitive, Zero};
+use num::{BigInt, BigUint, FromPrimitive, One, ToPrimitive, Zero};
use num::bigint::Sign::{Minus... | 1 | 388 | 83 |
6c98a5fa5e648f896901484655f3d767d6b52391 | Paul Mason | 2017-11-05T05:34:38 | Optimized mul operation | diff --git a/src/decimal.rs b/src/decimal.rs
index 7c78412..a4b0b51 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1283,41 +1283,108 @@ impl<'a, 'b> Mul<&'b Decimal> for &'a Decimal {
#[inline]
fn mul(self, other: &Decimal) -> Decimal {
- // Get big uints to work with
- let left = self.t... | 2 | 105 | 31 |
b324289adf7114375eea373673f9dfd023c0e0e5 | Paul Mason | 2017-11-05T04:11:12 | Optimized add/sub functions for Decimal | diff --git a/src/decimal.rs b/src/decimal.rs
index 8514a48..7c78412 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -324,7 +324,7 @@ impl Decimal {
}
}
- fn add_raw(value: &mut [u32; 3], by: &[u32; 3]) -> u32 {
+ fn add_internal(value: &mut [u32; 3], by: &[u32; 3]) -> u32 {
let mut ca... | 1 | 166 | 84 |
1bd9a2cc0d1434c2fd930012a2bb215765d0675c | Paul Mason | 2017-11-05T01:46:49 | Implementation for parsing floats into Decimals (#60)
* Float conversion tests
* Start of f32/f64 conversions
* Start of IEEE 754-1985 unpacking
* Start of raw bit manipulation for performance optimizations
* Fixes bug where most significant bit field was being missed
* Rust format changes
* Minor clean up of co... | diff --git a/benches/lib_benches.rs b/benches/lib_benches.rs
index 41ab737..18c7f12 100644
--- a/benches/lib_benches.rs
+++ b/benches/lib_benches.rs
@@ -3,10 +3,10 @@
extern crate test;
extern crate rust_decimal;
extern crate decimal;
-use test::Bencher;
-use rust_decimal::Decimal;
use decimal::d128;
+use rust_deci... | 5 | 490 | 78 |
db45eff2d1d41cc41788dcde5eb504d4d3c306a1 | Paul Mason | 2017-10-31T02:13:50 | Renamed variables for clarity | diff --git a/src/decimal.rs b/src/decimal.rs
index 1bd8c09..c6307af 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1051,12 +1051,12 @@ impl Ord for Decimal {
let oi = other.to_bigint();
if s > o {
let power = Decimal::power_10((s - o) as usize).to_bigint().unwrap();
- let... | 1 | 4 | 4 |
614213fc8c5394f07965b02915ce551ba4957112 | Paul Mason | 2017-10-31T02:07:13 | Fixes issue where cmp would panic due to invalid rescale | diff --git a/src/decimal.rs b/src/decimal.rs
index 1c1863c..1bd8c09 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -1,6 +1,7 @@
use Error;
use num::{BigInt, BigUint, FromPrimitive, Integer, One, ToPrimitive, Zero};
use num::bigint::Sign::{Minus, Plus};
+use num::bigint::ToBigInt;
use std::cmp::*;
use std::cmp... | 2 | 52 | 30 |
ba5a0a758f4ecb398ba4dd895d50471ae5bcb1f2 | Paul Mason | 2017-10-25T02:48:21 | Version 0.5.1 | diff --git a/Cargo.toml b/Cargo.toml
index 431725a..934294f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rust_decimal"
-version = "0.5.0"
+version = "0.5.1"
authors = ["Paul Mason <paul@form1.co.nz>"]
description = "A Decimal Implementation written in pure Rust suitable for financial... | 1 | 1 | 1 |
2e6edbe8a01aeedf88f2b3a0742383943de8d548 | Andrew Gallant | 2017-10-22T23:53:32 | parse: don't panic on empty strings
Fixes #55 | diff --git a/src/decimal.rs b/src/decimal.rs
index ee266f2..1c1863c 100644
--- a/src/decimal.rs
+++ b/src/decimal.rs
@@ -514,6 +514,9 @@ impl FromStr for Decimal {
type Err = Error;
fn from_str(value: &str) -> Result<Decimal, Self::Err> {
+ if value.is_empty() {
+ return Err(Error::new("In... | 2 | 9 | 0 |
1c7b98f066df4cfddbda99f65c29dbdc08576d4f | jek | 2017-10-06T00:36:57 | add basic benchmark against d128, closing #14 | diff --git a/Cargo.toml b/Cargo.toml
index 27740de..714cfad 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,6 +26,6 @@ serde = { version = "1.0", optional = true }
[dev-dependencies]
serde_json = "1.0"
serde_derive = "1.0"
-
+decimal = "2.0"
[features]
-default = ["serde"]
\ No newline at end of file
+default = ["s... | 2 | 46 | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.