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 |
|---|---|---|---|---|---|---|---|
1a15987c2cdb926d396cd46c67f819c0e44b3d22 | Andrew Kubera | 2023-10-15T18:50:39 | Reorganize and expand impl_ops_add.rs | diff --git a/src/impl_ops_add.rs b/src/impl_ops_add.rs
index 5bf37b0..4a02747 100644
--- a/src/impl_ops_add.rs
+++ b/src/impl_ops_add.rs
@@ -9,8 +9,14 @@ impl Add<BigDecimal> for BigDecimal {
#[inline]
fn add(self, rhs: BigDecimal) -> BigDecimal {
- let mut lhs = self;
+ if rhs.is_zero() {
+ ... | 1 | 177 | 31 |
6eeb387691d8a6b5ce93db6b619b6465770fd6dd | Andrew Kubera | 2023-10-15T17:42:55 | Fix and expand impl Sub<> | diff --git a/src/impl_ops_sub.rs b/src/impl_ops_sub.rs
index 82cd9d8..a640063 100644
--- a/src/impl_ops_sub.rs
+++ b/src/impl_ops_sub.rs
@@ -1,5 +1,5 @@
//!
-//! Multiplication operator trait implementation
+//! Subtraction operator trait implementation
//!
use crate::*;
@@ -19,111 +19,177 @@ impl Sub<BigDecimal> ... | 1 | 174 | 66 |
71f0d63c176143bab328637e8ba57e4957a116b3 | Andrew Kubera | 2023-10-15T04:04:41 | Impl Sub/SubAssign for BigDecimalRef | diff --git a/src/impl_ops_sub.rs b/src/impl_ops_sub.rs
index 1961682..82cd9d8 100644
--- a/src/impl_ops_sub.rs
+++ b/src/impl_ops_sub.rs
@@ -10,6 +10,14 @@ impl Sub<BigDecimal> for BigDecimal {
#[inline]
fn sub(self, rhs: BigDecimal) -> BigDecimal {
+ if rhs.is_zero() {
+ return self;
+ ... | 1 | 58 | 68 |
a61b5820d22ed1785f509baa14e9a188614d9a9a | Andrew Kubera | 2023-10-15T03:10:13 | to_owned_with_scale | diff --git a/src/lib.rs b/src/lib.rs
index a617bb5..878b06c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1251,6 +1251,36 @@ impl BigDecimalRef<'_> {
}
}
+ /// Clone digits, returning BigDecimal with given scale
+ ///
+ /// ```
+ /// # use bigdecimal::*;
+ ///
+ /// let n: BigDecimal = ... | 1 | 30 | 0 |
438084e2e0380c609005f1794bf0dee240c577af | Andrew Kubera | 2023-10-15T03:09:14 | Add BigDecimalRef::is_zero | diff --git a/src/lib.rs b/src/lib.rs
index 404587f..a617bb5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1293,6 +1293,11 @@ impl BigDecimalRef<'_> {
Plus => Some(arithmetic::sqrt::impl_sqrt(uint, scale, ctx)),
}
}
+
+ /// Return if the referenced decimal is zero
+ pub fn is_zero(&self) ... | 1 | 5 | 0 |
cb21dc3a2fd22e767cb1ddb8546833ea28c7c29f | Andrew Kubera | 2023-10-15T03:08:39 | Add fractional_digit_count to BigDecimalRef and expand tests and docs | diff --git a/src/lib.rs b/src/lib.rs
index 6b09ce6..404587f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -201,7 +201,9 @@ impl BigDecimal {
self.into()
}
- /// Returns the scale of the BigDecimal
+ /// Returns the scale of the BigDecimal, the total number of
+ /// digits to the right of the deci... | 1 | 22 | 2 |
a0fad26c270f0212b1b74de889143b9b3e683842 | John | 2023-10-15T01:54:55 | Add `fractional_digit_count` method to `BigDecimal` for efficient number type determination | diff --git a/src/lib.rs b/src/lib.rs
index c053eba..6b09ce6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -201,6 +201,25 @@ impl BigDecimal {
self.into()
}
+ /// Returns the scale of the BigDecimal
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use bigdecimal::BigDecimal;
+ /// use std:... | 1 | 34 | 0 |
72101874ce0d1e40295aa0d0f90168f91456b6ff | Andrew Kubera | 2023-10-15T01:31:49 | Fix another typo | diff --git a/src/impl_cmp.rs b/src/impl_cmp.rs
index ecef30a..32f7019 100644
--- a/src/impl_cmp.rs
+++ b/src/impl_cmp.rs
@@ -5,7 +5,7 @@
//! inference features at the savings of a single
//! '&' character.
//!
-//! &BigDecimal and BigDecimalRef are comparible.
+//! &BigDecimal and BigDecimalRef are comparable.
//!
... | 1 | 1 | 1 |
6c592b4566c83939d64569bfaf268c81e1e8deaf | Andrew Kubera | 2023-10-14T17:13:21 | Expand documentation of BigDecimalRef | diff --git a/src/lib.rs b/src/lib.rs
index 87ecebb..c053eba 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1171,17 +1171,44 @@ impl fmt::Debug for BigDecimal {
}
-/// A big-decimal wrapping a borrowed (immutable) buffer of digits
+/// Immutable big-decimal, referencing a borrowed buffer of digits
///
/// The non-d... | 1 | 31 | 4 |
bb185d912f39bf9acd7033b8970a6c3235f34c4e | Andrew Kubera | 2023-10-14T18:09:35 | Reorganize impl Add/AddAssign with BigDecimalRef | diff --git a/src/impl_ops_add.rs b/src/impl_ops_add.rs
index 525eab1..5bf37b0 100644
--- a/src/impl_ops_add.rs
+++ b/src/impl_ops_add.rs
@@ -25,15 +25,13 @@ impl Add<BigDecimal> for BigDecimal {
impl<'a, T: Into<BigDecimalRef<'a>>> Add<T> for BigDecimal {
type Output = BigDecimal;
- fn add(self, rhs: T) -> B... | 1 | 39 | 23 |
52d7e5ec42c7109945e4d1e4eff40df78b64edd1 | Andrew Kubera | 2023-10-14T18:07:06 | impl Add<primitive-int> for BigDecimalRef | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index 829f631..9cac1be 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -23,6 +23,14 @@ macro_rules! impl_add_for_primitive {
impl Add<$t> for &BigDecimal {
type Output = BigDecimal;
+ fn add(self, rhs: $t) -> BigDecimal {
+ ... | 1 | 8 | 0 |
ffd7988b85850882640964c5b22fa7b6519e1922 | Andrew Kubera | 2023-10-14T17:34:40 | Support Add & AddAssign BigDecimalRef | diff --git a/src/impl_ops_add.rs b/src/impl_ops_add.rs
index 6928139..525eab1 100644
--- a/src/impl_ops_add.rs
+++ b/src/impl_ops_add.rs
@@ -22,24 +22,17 @@ impl Add<BigDecimal> for BigDecimal {
}
}
-impl<'a> Add<&'a BigDecimal> for BigDecimal {
+impl<'a, T: Into<BigDecimalRef<'a>>> Add<T> for BigDecimal {
... | 1 | 17 | 51 |
837137f073bb3d5f47d8f6197e5ef299f45f2528 | Andrew Kubera | 2023-10-14T17:52:17 | Impl From<&BigInt> for BigDecimalRef | diff --git a/src/lib.rs b/src/lib.rs
index 7eec7d0..87ecebb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1249,6 +1249,16 @@ impl<'a> From<&'a BigDecimal> for BigDecimalRef<'a> {
}
}
+impl<'a> From<&'a BigInt> for BigDecimalRef<'a> {
+ fn from(n: &'a BigInt) -> Self {
+ Self {
+ sign: n.sign... | 1 | 10 | 0 |
4a772f5346744200baf4da2084e42f9f68f97795 | Andrew Kubera | 2023-10-14T17:01:51 | Remove pub modifier from rounding mod | diff --git a/src/lib.rs b/src/lib.rs
index 076e5a5..7eec7d0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -116,7 +116,7 @@ mod impl_num;
mod parsing;
// Routines for rounding
-pub mod rounding;
+mod rounding;
pub use rounding::RoundingMode;
// Mathematical context | 1 | 1 | 1 |
50995104dcafc2b867c8e1d671c0deb7a7f6024a | Andrew Kubera | 2023-10-15T00:30:20 | Mark BigDecimalRef::as_parts as used | diff --git a/src/lib.rs b/src/lib.rs
index 51949a0..076e5a5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1210,7 +1210,6 @@ impl BigDecimalRef<'_> {
}
/// Split into components
- #[allow(dead_code)]
pub(crate) fn as_parts(&self) -> (Sign, i64, &BigUint) {
(self.sign, self.scale, self.digits)... | 1 | 0 | 1 |
1105432264de42049d65cfcfbeabfe671ea17d7f | Andrew Kubera | 2023-10-12T01:33:38 | Fix clippy lints | diff --git a/src/arithmetic/inverse.rs b/src/arithmetic/inverse.rs
index 6a51289..e291707 100644
--- a/src/arithmetic/inverse.rs
+++ b/src/arithmetic/inverse.rs
@@ -43,7 +43,7 @@ pub(crate) fn impl_inverse_uint_scale(n: &BigUint, scale: i64, ctx: &Context) ->
fn make_inv_guess(bit_count: u64, scale: i64) -> BigDecim... | 3 | 3 | 4 |
4a30485c7d2eda391f7309d3f6f5afd7ede34ffd | Andrew Kubera | 2023-10-09T03:07:27 | Move sqrt tests into src/arithmetic/sqrt.rs | diff --git a/src/arithmetic/sqrt.rs b/src/arithmetic/sqrt.rs
index 1d52e8a..d2a56df 100644
--- a/src/arithmetic/sqrt.rs
+++ b/src/arithmetic/sqrt.rs
@@ -145,14 +145,65 @@ pub(crate) fn impl_sqrt(n: &BigUint, scale: i64, ctx: &Context) -> BigDecimal {
mod test {
use super::*;
+ #[test]
+ fn test_sqrt() {
+... | 2 | 73 | 55 |
3c9bb6f94a31c9e2eda85ccf84d72bb75a671115 | Andrew Kubera | 2023-10-09T00:46:25 | Move cbrt tests into src/arithmetic/cbrt.rs | diff --git a/src/arithmetic/cbrt.rs b/src/arithmetic/cbrt.rs
index fa0d959..8887fb9 100644
--- a/src/arithmetic/cbrt.rs
+++ b/src/arithmetic/cbrt.rs
@@ -5,7 +5,7 @@ use num_bigint::BigUint;
/// implementation of cuberoot - always positive
-pub(crate) fn impl_cbrt(n: &BigUint, scale: i64, ctx: &Context) -> BigDecim... | 2 | 71 | 21 |
584ddc526300e5e840da0f2dca0ca7b27890ed46 | Andrew Kubera | 2023-10-09T00:29:17 | Move implementation of inverse into src/arithmetic/inverse.rs | diff --git a/src/arithmetic/inverse.rs b/src/arithmetic/inverse.rs
new file mode 100644
index 0000000..6a51289
--- /dev/null
+++ b/src/arithmetic/inverse.rs
@@ -0,0 +1,146 @@
+//! inverse implementation
+
+use crate::*;
+
+/// Implementation of inverse: (1/n)
+pub(crate) fn impl_inverse_uint_scale(n: &BigUint, scale: i... | 3 | 156 | 50 |
ee4fcb23aba7300b6eab722af274f308c54648e4 | Andrew Kubera | 2023-10-08T19:26:46 | Move cbrt implementation to src/arithmetic/cbrt.rs | diff --git a/src/arithmetic/cbrt.rs b/src/arithmetic/cbrt.rs
new file mode 100644
index 0000000..fa0d959
--- /dev/null
+++ b/src/arithmetic/cbrt.rs
@@ -0,0 +1,84 @@
+//! Implementation of cube-root algorithm
+
+use crate::*;
+use num_bigint::BigUint;
+
+
+/// implementation of cuberoot - always positive
+pub(crate) fn ... | 3 | 95 | 58 |
f1e8d5f37201f99241935cabe7b4768c4d34befb | Andrew Kubera | 2023-10-08T19:30:14 | Add method take_with_sign | diff --git a/src/lib.rs b/src/lib.rs
index e43e27d..77d80cd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -356,6 +356,21 @@ impl BigDecimal {
}
}
+ /// Take and return bigdecimal with the given sign
+ ///
+ /// The Sign value `NoSign` is ignored: only use Plus & Minus
+ ///
+ pub(crate) fn ... | 1 | 15 | 0 |
8d4781af1d8fc31365aa8943cd50c6d88a08b7d7 | Andrew Kubera | 2023-10-08T18:18:28 | Fix typo in doc-comment | diff --git a/src/lib.rs b/src/lib.rs
index 9589404..e43e27d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -112,7 +112,7 @@ mod impl_cmp;
// Implementations of num_traits
mod impl_num;
-// construct BuildDecimals from strings and floats
+// construct BigDecimals from strings and floats
mod parsing;
// Routines for... | 1 | 1 | 1 |
8c2d713cceba7956aa1ed0dd1d5eb7f2ed0f791d | Andrew Kubera | 2023-10-02T02:18:06 | Correct minor typos | diff --git a/benches/arithmetic.rs b/benches/arithmetic.rs
index b6b3299..04ff995 100644
--- a/benches/arithmetic.rs
+++ b/benches/arithmetic.rs
@@ -1,4 +1,4 @@
-//! Benchmarks for arithmetic opertaion
+//! Benchmarks for arithmetic operation
extern crate criterion;
extern crate bigdecimal;
diff --git a/build.rs b/... | 4 | 4 | 4 |
62823c2a1b0ae0477832a0cde8057f3f776f3419 | Andrew Kubera | 2023-09-30T03:43:59 | Use crate::* in context | diff --git a/src/context.rs b/src/context.rs
index abab31f..d4931b7 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -1,23 +1,16 @@
//! Define arithmetical context
//!
-use crate::rounding::RoundingMode;
+use crate::*;
use stdlib::num::NonZeroU64;
-use stdlib;
-use num_traits::{ToPrimitive, Zero};
-
-use crat... | 1 | 2 | 9 |
cb2248905933cd75ccb00da75188cf7a20a3d904 | Andrew Kubera | 2023-09-29T06:25:34 | Add new implementation of sqrt using Context | diff --git a/src/arithmetic/mod.rs b/src/arithmetic/mod.rs
index 4938f1f..76b1b83 100644
--- a/src/arithmetic/mod.rs
+++ b/src/arithmetic/mod.rs
@@ -2,6 +2,7 @@
use crate::*;
+pub(crate) mod sqrt;
/// Return 10^pow
///
diff --git a/src/arithmetic/sqrt.rs b/src/arithmetic/sqrt.rs
new file mode 100644
index 0000... | 3 | 210 | 61 |
257a088bd766d1451ecd1ad04fdf69b374c97213 | Andrew Kubera | 2023-09-26T04:06:26 | Move ten_to_the and count_decimal_digits to arithmetic module | diff --git a/src/arithmetic/mod.rs b/src/arithmetic/mod.rs
new file mode 100644
index 0000000..4938f1f
--- /dev/null
+++ b/src/arithmetic/mod.rs
@@ -0,0 +1,73 @@
+//! arithmetic routines
+
+use crate::*;
+
+
+/// Return 10^pow
+///
+/// Try to calculate this with fewest number of allocations
+///
+pub(crate) fn ten_to_... | 2 | 82 | 69 |
3ee689cde63f2bcdcf7f71d076fdde754e402d63 | Andrew Kubera | 2023-09-30T00:16:53 | Ignore unused imports | diff --git a/src/lib.rs b/src/lib.rs
index b72f62c..6a04e3f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -46,6 +46,7 @@
#![allow(clippy::suspicious_arithmetic_impl)]
#![allow(clippy::suspicious_op_assign_impl)]
#![allow(clippy::redundant_field_names)]
+#![allow(unused_imports)]
pub extern crate num_bigint; | 1 | 1 | 0 |
8765b17ee97fff1e53f31ecff1eac1d114cfe659 | Andrew Kubera | 2023-09-29T00:18:48 | Implement RemAssign | diff --git a/src/impl_ops_rem.rs b/src/impl_ops_rem.rs
index 8a1dc1d..56bad43 100644
--- a/src/impl_ops_rem.rs
+++ b/src/impl_ops_rem.rs
@@ -79,6 +79,13 @@ impl<'a, 'b> Rem<&'b BigDecimal> for &'a BigDecimal {
}
}
+impl RemAssign<&BigDecimal> for BigDecimal {
+ fn rem_assign(&mut self, other: &BigDecimal) {
... | 2 | 11 | 1 |
97fe9706d078a55c5b1d107dcb47ed560b21602d | Andrew Kubera | 2023-09-29T00:08:17 | Clean 'use' statements | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index 8a02e36..829f631 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -1,21 +1,6 @@
//! Implement math operations: Add,Sub, etc
-use crate::{
- BigDecimal,
- BigDecimalRef,
-};
-use crate::stdlib::ops::{
- Add, AddAssign,
- Sub, SubAssign,
- Mul, M... | 6 | 19 | 63 |
b1c02acb5fce7ab05d5a16413e17ceedd1f7e2f3 | Andrew Kubera | 2023-09-27T23:48:48 | Move rem tests to impl_ops_rem.rs | diff --git a/src/impl_ops_rem.rs b/src/impl_ops_rem.rs
index 080d1b8..4a4e3a4 100644
--- a/src/impl_ops_rem.rs
+++ b/src/impl_ops_rem.rs
@@ -33,6 +33,7 @@ impl<'a> Rem<&'a BigDecimal> for BigDecimal {
BigDecimal::new(result, scale)
}
}
+
impl<'a> Rem<BigDecimal> for &'a BigDecimal {
type Output = B... | 2 | 78 | 49 |
135912c58aae47af079afbcecc9bb0e79896600c | Andrew Kubera | 2023-09-27T23:50:30 | Move impl Rem into impl_ops_rem.rs | diff --git a/src/impl_ops_rem.rs b/src/impl_ops_rem.rs
new file mode 100644
index 0000000..080d1b8
--- /dev/null
+++ b/src/impl_ops_rem.rs
@@ -0,0 +1,78 @@
+//! Remainder implementations
+
+use super::*;
+
+impl Rem<BigDecimal> for BigDecimal {
+ type Output = BigDecimal;
+
+ #[inline]
+ fn rem(self, other: Bi... | 2 | 79 | 75 |
c9c860a5d51da62d3dfe91f8a260c82399fd4d95 | Andrew Kubera | 2023-09-27T23:48:30 | Move division tests to impl_ops_div.rs | diff --git a/src/impl_ops_div.rs b/src/impl_ops_div.rs
index 2a2cee4..1a756bd 100644
--- a/src/impl_ops_div.rs
+++ b/src/impl_ops_div.rs
@@ -86,3 +86,71 @@ impl<'a, 'b> Div<&'b BigDecimal> for &'a BigDecimal {
return impl_division(num_int.clone(), den_int, scale, max_precision);
}
}
+
+
+#[cfg(test)]
+mo... | 2 | 68 | 62 |
e550656faa4a7290c4ac60a39158a8ea0824ce29 | Andrew Kubera | 2023-09-27T03:50:18 | Move impl Div into impl_ops_div.rs | diff --git a/src/impl_ops_div.rs b/src/impl_ops_div.rs
new file mode 100644
index 0000000..2a2cee4
--- /dev/null
+++ b/src/impl_ops_div.rs
@@ -0,0 +1,88 @@
+//! Implement division
+
+use super::*;
+
+impl Div<BigDecimal> for BigDecimal {
+ type Output = BigDecimal;
+ #[inline]
+ fn div(self, other: BigDecimal)... | 2 | 91 | 85 |
7bd7a28be90053ec3049f45c76f72cd426d445b6 | Andrew Kubera | 2023-09-25T05:37:06 | Move multiplication tests into impl_ops_mul | diff --git a/src/impl_ops_mul.rs b/src/impl_ops_mul.rs
index b6259d4..f13ec58 100644
--- a/src/impl_ops_mul.rs
+++ b/src/impl_ops_mul.rs
@@ -220,3 +220,77 @@ impl MulAssign<BigInt> for BigDecimal {
*self *= &rhs
}
}
+
+
+#[cfg(test)]
+#[allow(non_snake_case)]
+mod bigdecimal_tests {
+ use crate::{stdl... | 2 | 74 | 63 |
486b600a9764c25488557d90cdda68c8cdc7e367 | Andrew Kubera | 2023-09-25T05:33:38 | Move impl Mul & MulAssign into impl_ops_mul.rs | diff --git a/src/impl_ops_mul.rs b/src/impl_ops_mul.rs
new file mode 100644
index 0000000..b6259d4
--- /dev/null
+++ b/src/impl_ops_mul.rs
@@ -0,0 +1,222 @@
+//! Multiplication operator trait implementation
+//!
+
+use crate::{
+ Sign,
+ BigDecimal,
+ BigDecimalRef,
+};
+
+use crate::stdlib::{
+ mem::swap,
... | 2 | 224 | 206 |
140a3c797da2deba5093c6c0715f972e4c616dfb | Andrew Kubera | 2023-09-26T01:57:04 | Move subtraction tests into impl_ops_sub | diff --git a/src/impl_ops_sub.rs b/src/impl_ops_sub.rs
index 10a460d..a6e2502 100644
--- a/src/impl_ops_sub.rs
+++ b/src/impl_ops_sub.rs
@@ -183,3 +183,79 @@ impl<'a> SubAssign<&'a BigInt> for BigDecimal {
}
}
}
+
+
+#[cfg(test)]
+mod test {
+ use super::*;
+ use paste::paste;
+
+ macro_rules! i... | 2 | 76 | 26 |
3d119c837f0ea391cb5d4cbdd1f0c3018c8c818e | Andrew Kubera | 2023-09-25T05:50:17 | Move impl Sub and SubAssign into impl_ops_sub.rs | diff --git a/src/impl_ops_sub.rs b/src/impl_ops_sub.rs
new file mode 100644
index 0000000..10a460d
--- /dev/null
+++ b/src/impl_ops_sub.rs
@@ -0,0 +1,185 @@
+//!
+//! Multiplication operator trait implementation
+//!
+
+use crate::{
+ Sign,
+ BigDecimal,
+ BigDecimalRef,
+};
+
+use crate::stdlib::{
+ mem::s... | 2 | 187 | 167 |
d72efad0deefa0334072a29c7db4c0a2f6c4af7d | Andrew Kubera | 2023-09-26T01:39:23 | Move and expand addition tests in impl_ops_add.rs | diff --git a/src/impl_ops_add.rs b/src/impl_ops_add.rs
index 5020f03..0245311 100644
--- a/src/impl_ops_add.rs
+++ b/src/impl_ops_add.rs
@@ -178,3 +178,104 @@ impl<'a> AddAssign<&'a BigInt> for BigDecimal {
}
}
}
+
+
+#[cfg(test)]
+mod test {
+ use super::*;
+ use paste::paste;
+
+ macro_rules! ... | 2 | 101 | 28 |
85483d94e722a17530f7bfbcd2c8a65e50f80249 | Andrew Kubera | 2023-09-25T05:06:37 | Move impl Add & AddAssign to impl_ops_add.rs | diff --git a/src/impl_ops_add.rs b/src/impl_ops_add.rs
new file mode 100644
index 0000000..5020f03
--- /dev/null
+++ b/src/impl_ops_add.rs
@@ -0,0 +1,180 @@
+//! Addition operator trait implementation
+//!
+
+use crate::{
+ Sign,
+ BigDecimal,
+ BigDecimalRef,
+};
+
+use crate::stdlib::{
+ ops::{Add, AddAss... | 2 | 181 | 164 |
5e0f293690db5b2fd43dba10af26b26457b8866d | Andrew Kubera | 2023-09-24T18:17:38 | Add and use DEFAULT_ROUNDING_MODE compile-time configuration | diff --git a/build.rs b/build.rs
index ab99787..3c47214 100644
--- a/build.rs
+++ b/build.rs
@@ -1,7 +1,7 @@
-#![allow(clippy::style)]
use std::env;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
+
fn main() {
let ac = autocfg::new();
@@ -15,11 +15,12 @@ fn main() {
let outdir: PathBuf = st... | 2 | 18 | 4 |
78a11ef97a736fdc15efa125ec5418400e6f1003 | Andrew Kubera | 2023-09-16T00:41:08 | Add math Context struct | diff --git a/src/context.rs b/src/context.rs
new file mode 100644
index 0000000..32c66ac
--- /dev/null
+++ b/src/context.rs
@@ -0,0 +1,181 @@
+//! Define arithmetical context
+//!
+
+use crate::rounding::RoundingMode;
+use stdlib::num::NonZeroU64;
+use stdlib;
+
+use num_traits::{ToPrimitive, Zero};
+
+use crate::{
+ ... | 2 | 193 | 3 |
de40b5a879912def11fdde6e94920d157d361e66 | Andrew Kubera | 2023-09-24T03:50:05 | Add BigDecimalRef::as_parts method | diff --git a/src/lib.rs b/src/lib.rs
index d84ea46..0473b54 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2067,6 +2067,12 @@ impl BigDecimalRef<'_> {
count_decimal_digits_uint(self.digits)
}
+ /// Split into components
+ #[allow(dead_code)]
+ pub(crate) fn as_parts(&self) -> (Sign, i64, &BigUint... | 1 | 6 | 0 |
6b976d3420a73bcabacc07f131cfdb0ed9c50f6d | Andrew Kubera | 2023-09-15T06:09:48 | Fix compatibility with older rustc versions | diff --git a/build.rs b/build.rs
index 196093d..d0a0df7 100644
--- a/build.rs
+++ b/build.rs
@@ -7,6 +7,9 @@ fn main() {
let ac = autocfg::new();
ac.emit_rustc_version(1, 70);
+ // Option::zip
+ ac.emit_rustc_version(1, 46);
+
let outdir: PathBuf = std::env::var_os("OUT_DIR").unwrap().into();
... | 2 | 18 | 4 |
5cb081d1baeb4c97c1c5b4878759679c6d52bf40 | Andrew Kubera | 2023-09-15T05:11:45 | Add method BigDecimal::to_ref | diff --git a/src/impl_cmp.rs b/src/impl_cmp.rs
index c46dc14..feeaa43 100644
--- a/src/impl_cmp.rs
+++ b/src/impl_cmp.rs
@@ -20,7 +20,7 @@ use stdlib::iter;
impl PartialEq for BigDecimal
{
fn eq(&self, rhs: &BigDecimal) -> bool {
- self.take_ref() == rhs.take_ref()
+ self.to_ref() == rhs.to_ref()
... | 2 | 8 | 2 |
69a291574b7509739a88024f9f1510185ead41c8 | Andrew Kubera | 2023-09-15T05:10:21 | Move reimplementation of PartialEq into impl_cmp.rs | diff --git a/src/impl_cmp.rs b/src/impl_cmp.rs
new file mode 100644
index 0000000..c46dc14
--- /dev/null
+++ b/src/impl_cmp.rs
@@ -0,0 +1,99 @@
+//! Implementation of comparsion operations
+//!
+//! Comparisons between decimals and decimal refs
+//! are not directly supported as we lose some type
+//! inference feature... | 2 | 103 | 50 |
faa6a1277c7eb641b872b556ad3e585181fd2da8 | Andrew Kubera | 2023-09-15T05:03:35 | Move impl Neg of BigDecimal to impl_ops.rs | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index 3ca8d58..8a02e36 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -444,6 +444,25 @@ impl_div_for_primitive!(f32);
impl_div_for_primitive!(f64);
+impl Neg for BigDecimal {
+ type Output = BigDecimal;
+
+ #[inline]
+ fn neg(mut self) -> BigDecimal {
... | 2 | 19 | 18 |
dac45fa8f771f61ad19cc55f08ae241a48b90fd6 | Andrew Kubera | 2023-09-15T05:00:38 | Impl std::ops::Neg for BigDecimalRef | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index 8e91e60..3ca8d58 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -1,6 +1,9 @@
//! Implement math operations: Add,Sub, etc
-use crate::BigDecimal;
+use crate::{
+ BigDecimal,
+ BigDecimalRef,
+};
use crate::stdlib::ops::{
Add, AddAssign,
Sub,... | 1 | 17 | 1 |
e231abc512df4f9aed60c5adb0c341e00ce45ac3 | Andrew Kubera | 2023-09-15T04:55:33 | Add BigDecimalRef struct and impl | diff --git a/src/lib.rs b/src/lib.rs
index 83fef18..5087476 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -73,7 +73,7 @@ use self::stdlib::str::FromStr;
use self::stdlib::string::{String, ToString};
use self::stdlib::fmt;
-use num_bigint::{BigInt, ParseBigIntError, Sign};
+use num_bigint::{BigInt, BigUint, ParseBigIn... | 1 | 76 | 4 |
9520e969024be6349f0d6bdbed614ac3e40fb809 | Andrew Kubera | 2023-09-15T03:07:51 | Add BigDecimal::with_precision_round method | diff --git a/src/lib.rs b/src/lib.rs
index 8277e35..83fef18 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -426,6 +426,21 @@ impl BigDecimal {
}
}
+ /// Return this BigDecimal with the given precision, rounding if needed
+ pub fn with_precision_round(&self, prec: stdlib::num::NonZeroU64, round: Round... | 1 | 15 | 0 |
d1bfee282865a05b9203249539bc467d4a69fb0c | Andrew Kubera | 2023-08-16T03:31:13 | Replace custom LOG2_10 with value from f64::consts | diff --git a/src/lib.rs b/src/lib.rs
index e058436..8277e35 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -77,8 +77,7 @@ use num_bigint::{BigInt, ParseBigIntError, Sign};
use num_integer::Integer as IntegerTrait;
pub use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
-#[allow(clippy::approx_constan... | 1 | 1 | 2 |
4d4872fbe5c005247ce5597f7b81091679fff57b | Andrew Kubera | 2023-08-20T17:16:03 | Move write_default_precision_file back to separate function | diff --git a/build.rs b/build.rs
index f60cfe1..196093d 100644
--- a/build.rs
+++ b/build.rs
@@ -7,11 +7,17 @@ fn main() {
let ac = autocfg::new();
ac.emit_rustc_version(1, 70);
+ let outdir: PathBuf = std::env::var_os("OUT_DIR").unwrap().into();
+ write_default_precision_file(&outdir);
+}
+
+
+/// Cr... | 1 | 9 | 3 |
1a5b6c0e3bcb0af138a850ffb3543af0180adc79 | Lucas Kent | 2023-08-20T17:07:36 | Fix use of rerun-if-changed and clean build.rs | diff --git a/build.rs b/build.rs
index 7b35ce4..f60cfe1 100644
--- a/build.rs
+++ b/build.rs
@@ -1,50 +1,24 @@
#![allow(clippy::style)]
-extern crate autocfg;
-
use std::env;
use std::path::PathBuf;
-
-fn main() -> std::io::Result<()> {
+fn main() {
let ac = autocfg::new();
ac.emit_rustc_version(1, 70)... | 1 | 12 | 38 |
3c03767bf6b9e876fce6fe150d42e52d8104ddde | Andrew Kubera | 2023-08-16T00:15:54 | Hide artihmetic bench config behind toml comments | diff --git a/Cargo.toml b/Cargo.toml
index d395b27..85556b6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -47,6 +47,6 @@ default = ["std"]
string-only = []
std = ["num-bigint/std", "num-integer/std", "num-traits/std"]
-[[bench]]
-name = "arithmetic"
-harness = false
+# BENCH: [[bench]]
+# BENCH: name = "arithmetic"
+... | 1 | 3 | 3 |
cce036106b3d7cd9499f4abd9bb308b2c540397a | Andrew Kubera | 2023-07-28T18:23:56 | Reimplement ten_to_the | diff --git a/src/lib.rs b/src/lib.rs
index a1c23dc..e058436 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -102,27 +102,50 @@ mod parsing;
pub mod rounding;
pub use rounding::RoundingMode;
-#[inline(always)]
+/// Return 10^pow
+///
+/// Try to calculate this with fewest number of allocations
+///
fn ten_to_the(pow: u... | 1 | 35 | 12 |
94e2145d1bead3d7266b1f4335ddbe4bdf9b748e | Andrew Kubera | 2023-07-25T04:56:41 | Reimplement BigDecimal::eq | diff --git a/src/lib.rs b/src/lib.rs
index a77801b..a1c23dc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -68,7 +68,7 @@ use self::stdlib::default::Default;
use self::stdlib::hash::{Hash, Hasher};
use self::stdlib::num::{ParseFloatError, ParseIntError};
use self::stdlib::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg,... | 1 | 39 | 7 |
219df989b433de72675ba419cfc7587173047b4c | Andrew Kubera | 2023-07-25T04:09:07 | Add Vec to stdlib | diff --git a/src/with_std.rs b/src/with_std.rs
index 4cddf7c..4ae185b 100644
--- a/src/with_std.rs
+++ b/src/with_std.rs
@@ -23,4 +23,6 @@ mod stdlib {
#[cfg(test)]
pub use std::collections::hash_map::DefaultHasher;
+
+ pub use std::vec::Vec;
}
diff --git a/src/without_std.rs b/src/without_std.rs
index ... | 2 | 3 | 0 |
113d5e59713fc4267b99d773bf0d6b62e9f8094e | Andrew Kubera | 2023-07-13T04:01:20 | Begin v0.4.2 development | diff --git a/Cargo.toml b/Cargo.toml
index 25c2935..d395b27 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bigdecimal"
-version = "0.4.1"
+version = "0.4.2+dev"
authors = ["Andrew Kubera"]
description = "Arbitrary precision decimal numbers"
documentation = "https://docs.rs/bigdecimal" | 1 | 1 | 1 |
1fc48f58fde25607a27a0ab083b788c4abf8420e | Andrew Kubera | 2023-07-13T03:47:25 | Version 0.4.1 | diff --git a/Cargo.toml b/Cargo.toml
index e6ca6fc..25c2935 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bigdecimal"
-version = "0.4.1+dev"
+version = "0.4.1"
authors = ["Andrew Kubera"]
description = "Arbitrary precision decimal numbers"
documentation = "https://docs.rs/bigdecimal" | 1 | 1 | 1 |
ccb6ccf6bb2b01c613ac64509778fc62a16561af | Andrew Kubera | 2023-07-13T03:39:44 | Add alternative implementation of Div<int> for older versions | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index c7b0e37..8e91e60 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -253,6 +253,7 @@ macro_rules! impl_div_for_primitive {
impl Div<$t> for BigDecimal {
type Output = BigDecimal;
+ #[cfg(rustc_1_70)] // Option::is_some_and
... | 1 | 16 | 0 |
208831c06a662979ce73adb2c534cc857390b123 | Andrew Kubera | 2023-07-13T03:33:57 | Add autocfg to probe rust version | diff --git a/Cargo.toml b/Cargo.toml
index d5278a8..e6ca6fc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,6 +39,9 @@ siphasher = { version = "0.3.10", default-features = false }
# Only required for property testing - incompatible with older versions of rust
# PROPERTY-TESTS: proptest = "1"
+[build-dependencies]
+... | 2 | 8 | 0 |
35108702cd224f70135b804c7d1c0911a9722242 | Andrew Kubera | 2023-07-13T03:19:59 | Pin serde json to 1.0.96 | diff --git a/Cargo.toml b/Cargo.toml
index 302c713..d5278a8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,7 +28,7 @@ serde = { version = "1.0", optional = true, default-features = false }
[dev-dependencies]
paste = "1"
-serde_json = "1.0"
+serde_json = "<1.0.101"
siphasher = { version = "0.3.10", default-feature... | 1 | 1 | 1 |
1d4f1d8a0000c65c5b0de566f136eff1719dedfb | Andrew Kubera | 2023-07-13T00:12:34 | Add property-tests file | diff --git a/src/lib.tests.property-tests.rs b/src/lib.tests.property-tests.rs
index e69de29..4327bda 100644
--- a/src/lib.tests.property-tests.rs
+++ b/src/lib.tests.property-tests.rs
@@ -0,0 +1,120 @@
+// Property tests to be included by lib.rs (if enabled)
+
+
+mod arithmetic {
+ use super::*;
+
+ macro_rules!... | 1 | 120 | 0 |
65f9f8f8a450049dc49c8b6eb306ce54e67ca862 | Andrew Kubera | 2023-07-13T03:11:07 | Fix some rustfmt issues | diff --git a/src/rounding.rs b/src/rounding.rs
index a1053d5..bbce7f1 100644
--- a/src/rounding.rs
+++ b/src/rounding.rs
@@ -172,7 +172,13 @@ impl RoundingMode {
/// Calculation of pair of digits from full number, and the replacement of that number
/// should be handled separately
///
- pub fn round_u... | 1 | 8 | 2 |
50ec8e4470897b662b052d333c422f5bd7006bc7 | Andrew Kubera | 2023-07-13T02:18:39 | Move impl Div<{primitive}> to impl_ops | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index 4eb6063..c7b0e37 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -5,9 +5,13 @@ use crate::stdlib::ops::{
Add, AddAssign,
Sub, SubAssign,
Mul, MulAssign,
+ Div, DivAssign,
Neg,
};
+
+use crate::stdlib::convert::TryFrom;
+
use num_trait... | 3 | 193 | 187 |
2800aa309cc893efc702572c02018d436703afc2 | Andrew Kubera | 2023-07-11T07:12:35 | Impl Mul<{int}> and MulAssign<{int}> | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index 4ecbc99..4eb6063 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -4,9 +4,13 @@ use crate::BigDecimal;
use crate::stdlib::ops::{
Add, AddAssign,
Sub, SubAssign,
+ Mul, MulAssign,
Neg,
};
+use num_traits::{Zero, One};
+
+
macro_rules! impl_... | 1 | 74 | 0 |
ec2a606eb91b9011f013f71853f023a77152f9be | Andrew Kubera | 2023-07-11T06:58:48 | Impl Sub<{int}> and SubAssign<{int}> | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
index e44b8e9..4ecbc99 100644
--- a/src/impl_ops.rs
+++ b/src/impl_ops.rs
@@ -3,6 +3,8 @@
use crate::BigDecimal;
use crate::stdlib::ops::{
Add, AddAssign,
+ Sub, SubAssign,
+ Neg,
};
macro_rules! impl_add_for_primitive {
@@ -79,3 +81,78 @@ impl_add_for_pri... | 1 | 77 | 0 |
a86fa5e9700e568c4c38bdea43d7892166df267b | Andrew Kubera | 2023-07-11T06:34:21 | Impl Add<{int}> and AddAssign<{int}> in impl_ops.rs | diff --git a/src/impl_ops.rs b/src/impl_ops.rs
new file mode 100644
index 0000000..e44b8e9
--- /dev/null
+++ b/src/impl_ops.rs
@@ -0,0 +1,81 @@
+//! Implement math operations: Add,Sub, etc
+
+use crate::BigDecimal;
+use crate::stdlib::ops::{
+ Add, AddAssign,
+};
+
+macro_rules! impl_add_for_primitive {
+ ($t:ty)... | 2 | 83 | 0 |
69efb943fe2cf057596728ea27bcf8ceb75facae | Andrew Kubera | 2023-07-11T06:19:41 | Move num-trait implementations to impl_num | diff --git a/src/impl_num.rs b/src/impl_num.rs
new file mode 100644
index 0000000..4953cd1
--- /dev/null
+++ b/src/impl_num.rs
@@ -0,0 +1,165 @@
+//! Code for num_traits
+
+use num_traits::{Num, FromPrimitive, ToPrimitive, AsPrimitive};
+use num_bigint::{BigInt, Sign, ToBigInt};
+
+use stdlib::str::FromStr;
+use stdlib... | 2 | 169 | 142 |
7f6dde94983200f06beb88a60d4376b901077a8a | Andrew Kubera | 2023-07-11T06:12:32 | Move impl From<BigInt> to impl_convert | diff --git a/src/impl_convert.rs b/src/impl_convert.rs
index ff3f955..2ab308f 100644
--- a/src/impl_convert.rs
+++ b/src/impl_convert.rs
@@ -3,6 +3,8 @@
use crate::BigDecimal;
use crate::stdlib::convert::TryFrom;
+use num_bigint::BigInt;
+
macro_rules! impl_from_int_primitive {
($t:ty) => {
@@ -55,3 +57,24 ... | 2 | 23 | 21 |
b405d06cf05870141f7fb092f99b6a0d82c4faca | Andrew Kubera | 2023-07-11T06:07:06 | Move impls of TryFrom<f{32,64}> into impl_convert | diff --git a/src/impl_convert.rs b/src/impl_convert.rs
index 35185e8..ff3f955 100644
--- a/src/impl_convert.rs
+++ b/src/impl_convert.rs
@@ -1,6 +1,7 @@
//! Code for implementing From/To BigDecimals
-use super::BigDecimal;
+use crate::BigDecimal;
+use crate::stdlib::convert::TryFrom;
macro_rules! impl_from_int_... | 2 | 21 | 19 |
4fa34f33ebea971521d26233a2ddbd4de45a0579 | Andrew Kubera | 2023-07-11T06:04:34 | Move implementation of From<{int}> and From<&{int}> to impl_convert.rs | diff --git a/src/impl_convert.rs b/src/impl_convert.rs
new file mode 100644
index 0000000..35185e8
--- /dev/null
+++ b/src/impl_convert.rs
@@ -0,0 +1,37 @@
+//! Code for implementing From/To BigDecimals
+
+use super::BigDecimal;
+
+
+macro_rules! impl_from_int_primitive {
+ ($t:ty) => {
+ impl From<$t> for Bi... | 2 | 40 | 56 |
c274173b3db32be6d827976a40c9526c3785e056 | Andrew Lamb | 2023-07-09T23:36:19 | Fix build.rs so rebuild is not always triggered by writing default-precision.rs file
Co-authored-by: Andrew Kubera <andrewkubera@gmail.com> | diff --git a/build.rs b/build.rs
index 8bc8be9..b520ea6 100644
--- a/build.rs
+++ b/build.rs
@@ -2,8 +2,6 @@
use std::env;
-use std::fs::File;
-use std::io::Write;
use std::path::PathBuf;
fn main() -> std::io::Result<()> {
@@ -28,8 +26,17 @@ fn write_default_precision(outdir_path: &PathBuf, filename: &str) -> ... | 1 | 11 | 4 |
b80509a8be4d77149388311a486c754cb4bb1a76 | Andrew Kubera | 2023-07-05T06:45:20 | Begin v0.4.1 development | diff --git a/Cargo.toml b/Cargo.toml
index 8ae8805..bb51afb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bigdecimal"
-version = "0.4.0"
+version = "0.4.1+dev"
authors = ["Andrew Kubera"]
description = "Arbitrary precision decimal numbers"
documentation = "https://docs.rs/bigdecimal" | 1 | 1 | 1 |
60ac44071c92c383a31ceeb464f9aa0944c4ce46 | Andrew Kubera | 2023-07-05T06:12:22 | Remove extra keywords from Cargo.toml metadata | diff --git a/Cargo.toml b/Cargo.toml
index 1378c74..7d27d76 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,14 +7,12 @@ documentation = "https://docs.rs/bigdecimal"
homepage = "https://github.com/akubera/bigdecimal-rs"
repository = "https://github.com/akubera/bigdecimal-rs"
keywords = [
- "mathematics",
"nume... | 1 | 1 | 3 |
bb31fda0375d3da31274735a80f537b7296517ef | Andrew Kubera | 2023-07-04T19:16:47 | Move tests of double to separate test file | diff --git a/src/lib.rs b/src/lib.rs
index 54c5a2a..ff06a97 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2396,10 +2396,12 @@ mod bigdecimal_serde {
#[rustfmt::skip]
#[cfg(test)]
+#[allow(non_snake_case)]
mod bigdecimal_tests {
use crate::{stdlib, BigDecimal, ToString, FromStr, TryFrom};
use num_traits::{... | 2 | 31 | 17 |
a61b74cc8d41ee9e123fb14ff6f4c79bcbb3e129 | Andrew Kubera | 2023-07-04T18:29:39 | Improve BigDecimal docstrings and doctests | diff --git a/src/lib.rs b/src/lib.rs
index 572c6b1..54c5a2a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -243,6 +243,16 @@ impl BigDecimal {
}
/// Return a new BigDecimal after shortening the digits and rounding
+ ///
+ /// ```
+ /// # use bigdecimal::*;
+ ///
+ /// let n: BigDecimal = "129.41... | 1 | 113 | 27 |
7b616ed325993d4c837cb21ad577d1bf9c60489f | Andrew Kubera | 2023-07-04T03:08:24 | Fix some clippy warnings | diff --git a/src/lib.rs b/src/lib.rs
index 46a22f2..3d01bab 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -844,7 +844,7 @@ impl BigDecimal {
}
let (sign, mut digits) = self.int_val.to_radix_be(10);
let trailing_count = digits.iter().rev().take_while(|i| **i == 0).count();
- let trunc_to ... | 1 | 5 | 8 |
b6a12fe6062b8ef5da9cf09aac9c3dd61ec44c1b | Andrew Kubera | 2023-06-06T04:28:36 | Add tests for with_scale_round | diff --git a/src/lib.rs b/src/lib.rs
index 48cf190..a4bafcf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3400,3 +3400,13 @@ mod bigdecimal_tests {
assert_eq!(value, expected);
}
}
+
+
+#[cfg(test)]
+#[allow(non_snake_case)]
+mod test_with_scale_round {
+ use super::*;
+ use paste::paste;
+
+ inc... | 2 | 123 | 0 |
c291f81b5d708b0503c6f880b16bef7dfcd703bc | Andrew Kubera | 2023-06-06T04:25:42 | Implement with_scale_round | diff --git a/src/lib.rs b/src/lib.rs
index de98ab1..48cf190 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -91,6 +91,7 @@ extern crate paste;
mod parsing;
pub mod rounding;
+pub use rounding::RoundingMode;
#[inline(always)]
fn ten_to_the(pow: u64) -> BigInt {
@@ -240,6 +241,83 @@ impl BigDecimal {
}
... | 1 | 78 | 0 |
dc83ac8196280c46ed6821c901b0cd623c3510ce | Andrew Kubera | 2023-06-04T22:30:02 | Fix missing rerun-if-env-changed bug in build.rs | diff --git a/build.rs b/build.rs
index a299729..f01fd1d 100644
--- a/build.rs
+++ b/build.rs
@@ -30,6 +30,7 @@ fn write_default_precision(outdir_path: &PathBuf, filename: &str) -> std::io::Re
write!(default_precision_rs, "const DEFAULT_PRECISION: u64 = {};", default_prec)?;
println!("cargo:rerun-if-changed=... | 1 | 1 | 0 |
4fafd2b0d604aa3d3c3146b4a8a757556f106bee | Andrew Kubera | 2023-06-04T21:23:42 | Replace remaining hardcoded values of max_precision | diff --git a/src/lib.rs b/src/lib.rs
index 9ce8108..de98ab1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1555,7 +1555,7 @@ impl Div<BigDecimal> for BigDecimal {
};
}
- let max_precision = 100;
+ let max_precision = DEFAULT_PRECISION;
return impl_division(self.int_val, &o... | 1 | 3 | 3 |
89081c7beb5e2ebd22c04b05eecabec3868dc0a9 | Andrew Kubera | 2023-06-02T04:37:42 | Add explicit checks to from_[iu]128 unit tests | diff --git a/src/lib.rs b/src/lib.rs
index 97ebd13..9ce8108 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3310,11 +3310,15 @@ mod bigdecimal_tests {
#[test]
fn test_from_i128() {
- BigDecimal::from_i128(-368934881474191032320).unwrap();
+ let value = BigDecimal::from_i128(-368934881474191032320)... | 1 | 6 | 2 |
7d4c77c347cdcacdee13f38bd3a698c1f039c5e5 | qdrs | 2023-05-31T05:02:03 | add basic unit tests | diff --git a/src/lib.rs b/src/lib.rs
index 98035b5..97ebd13 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3307,4 +3307,14 @@ mod bigdecimal_tests {
fn test_bad_string_only_decimal_and_exponent() {
BigDecimal::from_str(".e4").unwrap();
}
+
+ #[test]
+ fn test_from_i128() {
+ BigDecimal::fro... | 1 | 10 | 0 |
479515766fe137acc4fce3e28ac306e67513c4a2 | qdrs | 2023-05-30T16:08:09 | override default FromPrimitive implementation for u128 and i128 | diff --git a/src/lib.rs b/src/lib.rs
index 55e8884..98035b5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1954,6 +1954,24 @@ impl From<u64> for BigDecimal {
}
}
+impl From<i128> for BigDecimal {
+ fn from(n: i128) -> Self {
+ BigDecimal {
+ int_val: BigInt::from(n),
+ scale: 0,
+ ... | 1 | 28 | 0 |
85a8a87d4be228f5a095d512885c7a3d18dc9423 | Andrew Kubera | 2023-06-04T17:51:10 | Restructure rounding tests | diff --git a/src/rounding.rs b/src/rounding.rs
index 2c2264d..a1053d5 100644
--- a/src/rounding.rs
+++ b/src/rounding.rs
@@ -215,22 +215,19 @@ mod test_round_pair {
}
macro_rules! define_test_input {
- ( - $lhs:literal, $rhs:literal $($t:tt)* ) => {
- define_test_input!(sign=Sign::Minus, p... | 1 | 132 | 34 |
8ec0326529dc2f919b3183ff30978dd65d9c212e | Andrew Kubera | 2023-06-03T06:01:59 | Add macros and BigDecimal building functions to benches::common | diff --git a/benches/arithmetic.rs b/benches/arithmetic.rs
index 222c40a..b6b3299 100644
--- a/benches/arithmetic.rs
+++ b/benches/arithmetic.rs
@@ -3,6 +3,9 @@
extern crate criterion;
extern crate bigdecimal;
extern crate oorandom;
+extern crate lazy_static;
+
+use lazy_static::lazy_static;
use std::fs::File;
u... | 2 | 64 | 17 |
a865601b9334e022f8d5d29bbcf3ff4881dfdf9e | Andrew Kubera | 2023-06-01T01:49:32 | Create arithmetic benches | diff --git a/benches/arithmetic.rs b/benches/arithmetic.rs
new file mode 100644
index 0000000..222c40a
--- /dev/null
+++ b/benches/arithmetic.rs
@@ -0,0 +1,335 @@
+//! Benchmarks for arithmetic opertaion
+
+extern crate criterion;
+extern crate bigdecimal;
+extern crate oorandom;
+
+use std::fs::File;
+use std::time::D... | 2 | 374 | 0 |
52d553bfcdf7403e961e12264ea482a1d4a68ea7 | Andrew Kubera | 2023-04-19T02:32:00 | Add benchmark fields and dependencies to Cargo.toml | diff --git a/Cargo.toml b/Cargo.toml
index 9925b59..a2bc4f9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,6 +16,10 @@ keywords = [
"no-std",
]
license = "MIT/Apache-2.0"
+autobenches = false
+
+[lib]
+bench = false
[dependencies]
libm = "0.2.6"
@@ -28,8 +32,15 @@ serde = { version = "1.0", optional = true,... | 1 | 11 | 0 |
2128c9e4165ea9ac78553b36478f062da0ca63db | Andrew Kubera | 2023-05-31T05:26:18 | Fix stdlib usage in bigdecimal_serde | diff --git a/src/lib.rs b/src/lib.rs
index eaec869..55e8884 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2043,9 +2043,7 @@ impl ToBigInt for BigDecimal {
/// Tools to help serializing/deserializing `BigDecimal`s
#[cfg(feature = "serde")]
mod bigdecimal_serde {
- use stdlib::{fmt, TryFrom, FromStr};
-
- use sup... | 1 | 1 | 7 |
04d6ec09a5ab2173ffb3ddfffc1e5f6216d0ee76 | Andrew Kubera | 2023-05-27T22:40:36 | Add test_round_u32 | diff --git a/src/rounding.rs b/src/rounding.rs
index be4b23d..2c2264d 100644
--- a/src/rounding.rs
+++ b/src/rounding.rs
@@ -297,3 +297,71 @@ mod test_round_pair {
impl_test!(Up, Down, Ceiling, Floor, HalfUp, HalfDown, HalfEven => 2);
}
}
+
+
+#[cfg(test)]
+#[allow(non_snake_case)]
+mod test_round_u32 {
... | 1 | 68 | 0 |
086b42b6b87395159cca74a42433d445db1f3fe9 | Andrew Kubera | 2023-05-27T21:50:56 | Add method round_u32 to RoundingMode | diff --git a/src/rounding.rs b/src/rounding.rs
index 4ee5e81..be4b23d 100644
--- a/src/rounding.rs
+++ b/src/rounding.rs
@@ -1,6 +1,7 @@
//! Rounding structures and subroutines
use crate::Sign;
+use stdlib;
/// Determines how to calculate the last digit of the number
///
@@ -147,6 +148,47 @@ impl RoundingMode {... | 1 | 42 | 0 |
35bd3d8ecb7f41786e074a1a83166c09dac2af1c | Andrew Kubera | 2023-05-27T18:26:38 | Add tests for RoundingMode::round_pair | diff --git a/src/rounding.rs b/src/rounding.rs
index fa85c2f..4ee5e81 100644
--- a/src/rounding.rs
+++ b/src/rounding.rs
@@ -148,3 +148,110 @@ impl RoundingMode {
}
}
}
+
+
+#[cfg(test)]
+#[allow(non_snake_case)]
+mod test_round_pair {
+ use paste::paste;
+ use super::*;
+
+ macro_rules! impl_te... | 1 | 107 | 0 |
93abcb2a27354e98e929b54fddffaf7a6f13736c | Andrew Kubera | 2022-08-24T03:58:00 | Add RountingMode method for rounding a pair of digits | diff --git a/src/rounding.rs b/src/rounding.rs
index 30dc9ea..fa85c2f 100644
--- a/src/rounding.rs
+++ b/src/rounding.rs
@@ -95,3 +95,56 @@ pub enum RoundingMode {
///
HalfEven,
}
+
+
+impl RoundingMode {
+ /// Perform the rounding operation
+ ///
+ /// Parameters
+ /// ----------
+ /// * sign... | 1 | 53 | 0 |
bdbb94bd3a6160af75e6ff087a11f2323d55532e | Andrew Kubera | 2017-08-26T00:41:36 | Add rounding module with RoundingMode enum | diff --git a/src/lib.rs b/src/lib.rs
index 5ac9912..eaec869 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -90,6 +90,7 @@ mod macros;
extern crate paste;
mod parsing;
+pub mod rounding;
#[inline(always)]
fn ten_to_the(pow: u64) -> BigInt {
diff --git a/src/rounding.rs b/src/rounding.rs
new file mode 100644
index 0... | 2 | 98 | 0 |
91c78d3f114bdc5e648466dfaafcf4de16aad817 | Andrew Kubera | 2023-05-27T18:09:52 | Wrap std:: or core:: modules in namespace module 'stdlib' | diff --git a/src/lib.rs b/src/lib.rs
index 34492ca..5ac9912 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -60,15 +60,17 @@ include!("./with_std.rs");
#[cfg(not(feature = "std"))]
include!("./without_std.rs");
-use crate::cmp::Ordering;
-use crate::convert::TryFrom;
-use crate::default::Default;
-use crate::hash::{Has... | 6 | 97 | 83 |
7c48a7c105a9f1992105ebbbf6547384f7c8f155 | Andrew Kubera | 2023-05-27T07:31:17 | Use DEFAULT_PRECISION in BigDecimal::{sqrt,cbrt,inverse} | diff --git a/src/lib.rs b/src/lib.rs
index 52aa804..34492ca 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -450,7 +450,7 @@ impl BigDecimal {
// }
// TODO: Use context variable to set precision
- let max_precision = 100;
+ let max_precision = DEFAULT_PRECISION;
let next_iterati... | 1 | 3 | 3 |
dcc3174c789d4bc19463d0ad478701ac7f41b11b | Andrew Kubera | 2023-05-27T07:29:55 | Use DEFAULT_PRECISION in BigDecimal::exp | diff --git a/src/lib.rs b/src/lib.rs
index 25a2bb6..52aa804 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -731,6 +731,8 @@ impl BigDecimal {
return BigDecimal::one();
}
+ let target_precision = DEFAULT_PRECISION;
+
let precision = self.digits();
let mut term = self.clone... | 1 | 5 | 3 |
c67009ad05c2611a3994b17708106cdd49be92ea | Andrew Kubera | 2023-05-27T07:21:44 | Include default_precision.rs in lib.rs | diff --git a/src/lib.rs b/src/lib.rs
index 42e7731..25a2bb6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -77,6 +77,10 @@ pub use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
#[allow(clippy::approx_constant)] // requires Rust 1.43.0
const LOG2_10: f64 = 3.321928094887362_f64;
+
+// const DEFAULT_... | 1 | 4 | 0 |
b35a851246465f724fde83397ab257bbef48dd32 | Andrew Kubera | 2023-05-27T07:19:52 | Add build.rs which generates the default_precision.rs file | diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..a299729
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,35 @@
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::path::PathBuf;
+
+fn main() -> std::io::Result<()> {
+ let outdir = match std::env::var_os("OUT_DIR") {
+ None => retur... | 1 | 35 | 0 |
cfcf7fea75b1b8878c0c14e766436824a1e2cd9f | Andrew Kubera | 2023-03-20T03:31:10 | Add more rounding test cases | diff --git a/src/lib.rs b/src/lib.rs
index 3400ff4..42e7731 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2867,15 +2867,28 @@ mod bigdecimal_tests {
("1.444445", 1, "1.4"),
("1.44", 1, "1.4"),
("0.444", 2, "0.44"),
+ ("4.5", 0, "4"),
+ ("4.05", 1, "4.0"),
+ ... | 1 | 14 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.